Skip to content

Commit

Permalink
test: add test for classes as implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Oct 2, 2024
1 parent 2650a4a commit 0168f34
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/class.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,30 @@ describe('class mock', () => {
expect(fnScoped.calls).toEqual([['some', 'text', 1]])
})
})

test('accepts classes as implementation', () => {
let constructed = false
const Mock = spy(
class _Mock {
constructor(public name: string) {
constructed = true
}
}
)
const result = new Mock('Max')

expect(result.name).toBe('Max')
expect(constructed).toBe(true)
expect(Mock.calls).toEqual([['Max']])

expect(Mock.results[0][0]).toBe('ok')
expect(Mock.results[0][1]).toBe(result)
})

test('fals if class is called without the new keyword', () => {
const Mock = spy(class _Mock {})
expect(() => Mock()).toThrowError(
"Class constructor _Mock cannot be invoked without 'new'"
)
})
})

0 comments on commit 0168f34

Please sign in to comment.