-
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 2b8e9e8
Showing
2 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
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,31 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
import { useKeyMap } from '../hooks'; | ||
import { CodeMirrorEditor, KeyMap } from '../types'; | ||
|
||
describe('hooks', () => { | ||
describe('useKeyMap', () => { | ||
it('works correctly', () => { | ||
type KeyMap = Record<string, typeof jest.fn>; | ||
let keys: KeyMap = {}; | ||
const editor: Pick<CodeMirrorEditor, 'addKeyMap' | 'removeKeyMap'> = { | ||
addKeyMap: jest.fn(keyMap => { | ||
keys = { ...keys, ...(keyMap as KeyMap) }; | ||
}), | ||
removeKeyMap: jest.fn((key: string) => { | ||
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