-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: useKeyMap unmount removes keys (3778)
- Loading branch information
1 parent
e7915d8
commit f91730f
Showing
2 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
packages/graphiql-react/src/editor/__tests__/hooks.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
import { useKeyMap } from '../hooks'; | ||
import { CodeMirrorEditor, KeyMap } from '../types'; | ||
|
||
describe('hooks', () => { | ||
describe('useKeyMap', () => { | ||
it('works correctly', () => { | ||
let keys = {}; | ||
const editor: Pick<CodeMirrorEditor, 'addKeyMap' | 'removeKeyMap'> = { | ||
addKeyMap: jest.fn((keyMap: KeyMap) => { | ||
keys = { ...keys, ...keyMap }; | ||
}), | ||
removeKeyMap: jest.fn(key => { | ||
delete keys[key]; | ||
}), | ||
}; | ||
const callback = jest.fn(); | ||
const { unmount } = renderHook(() => | ||
useKeyMap( | ||
editor as unknown as CodeMirrorEditor, | ||
['foo', 'bar'], | ||
callback, | ||
), | ||
); | ||
expect(Object.keys(keys).length).toBe(2); | ||
unmount(); | ||
expect(Object.keys(keys).length).toBe(0); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters