Skip to content

Commit

Permalink
test: clear expected mock calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ph-fritsche committed Mar 13, 2021
1 parent a1c78bc commit 810c9a2
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions src/__tests__/keyboard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,34 @@ it('type asynchronous', async () => {
`)
})

it('error in sync', async () => {
const err = jest.spyOn(console, 'error')
err.mockImplementation(() => {})

userEvent.keyboard('{!')

// the catch will be asynchronous
await Promise.resolve()

expect(err).toHaveBeenCalledWith(expect.any(Error))
expect(err.mock.calls[0][0]).toHaveProperty(
'message',
'Expected key descriptor but found "!" in "{!"',
)
})

it('error in async', async () => {
const promise = userEvent.keyboard('{!', {delay: 1})

return expect(promise).rejects.toThrowError(
'Expected key descriptor but found "!" in "{!"',
)
describe('error', () => {
afterEach(() => {
;(console.error as jest.MockedFunction<typeof console.error>).mockClear()
})

it('error in sync', async () => {
const err = jest.spyOn(console, 'error')
err.mockImplementation(() => {})

userEvent.keyboard('{!')

// the catch will be asynchronous
await Promise.resolve()

expect(err).toHaveBeenCalledWith(expect.any(Error))
expect(err.mock.calls[0][0]).toHaveProperty(
'message',
'Expected key descriptor but found "!" in "{!"',
)
})

it('error in async', async () => {
const promise = userEvent.keyboard('{!', {delay: 1})

return expect(promise).rejects.toThrowError(
'Expected key descriptor but found "!" in "{!"',
)
})
})

it('continue typing with state', () => {
Expand Down

0 comments on commit 810c9a2

Please sign in to comment.