Skip to content

Commit

Permalink
- add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanlaschke committed Oct 4, 2023
1 parent caad32b commit 7d87cf5
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/useHotkeys.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,38 @@ test('should listen to multiple hotkeys', async () => {
expect(callback).toHaveBeenCalledTimes(2)
})

test('should be able to always output correct keys on multiple hotkeys', async () => {
const user = userEvent.setup()

const callbackA = jest.fn()
const callbackB = jest.fn()

renderHook(() => useHotkeys(['a'], callbackA))
renderHook(() => useHotkeys(['b'], callbackB))

await user.keyboard('{A>}')

expect(callbackA).toHaveBeenCalledTimes(1)

await user.keyboard('B')
expect(callbackA).toHaveBeenCalledTimes(1)
expect(callbackB).toHaveBeenCalledTimes(1)

await user.keyboard('C')

expect(callbackA).toHaveBeenCalledTimes(1)
expect(callbackB).toHaveBeenCalledTimes(1)

await user.keyboard('B')
expect(callbackA).toHaveBeenCalledTimes(1)
expect(callbackB).toHaveBeenCalledTimes(2)

await user.keyboard('{/A}')
expect(callbackA).toHaveBeenCalledTimes(1)
expect(callbackB).toHaveBeenCalledTimes(2)

})

test('should be able to parse first argument as string, array or readonly array', async () => {
const user = userEvent.setup()
const callback = jest.fn()
Expand Down

0 comments on commit 7d87cf5

Please sign in to comment.