Download wp-calypso/client/components/close-on-escape/test/index.jsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/components/close-on-escape/test/index.jsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/components/close-on-escape/test/index.jsx
-
curl -L -o index.jsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/components/close-on-escape/test/index.jsx
1.17 kB
| /** | |
| * @jest-environment jsdom | |
| */ | |
| import { render } from '@testing-library/react'; | |
| import CloseOnEscape from '../'; | |
| const simulateEscapeKeydown = () => | |
| document.dispatchEvent( new window.KeyboardEvent( 'keydown', { keyCode: 27 } ) ); | |
| describe( 'CloseOnEscape', () => { | |
| describe( 'rendering', () => { | |
| test( 'renders nothing', () => { | |
| const { container } = render( <CloseOnEscape /> ); | |
| expect( container ).toBeEmptyDOMElement(); | |
| } ); | |
| } ); | |
| describe( 'escape keydown event', () => { | |
| test( 'calls the `onEscape` method of stacked components in LIFO order on each escape keydown', () => { | |
| const onEscapeSpy = jest.fn(); | |
| const wrapper1 = render( | |
| <CloseOnEscape | |
| onEscape={ function () { | |
| onEscapeSpy( 1 ); | |
| wrapper1.unmount(); | |
| } } | |
| /> | |
| ); | |
| const wrapper2 = render( | |
| <CloseOnEscape | |
| onEscape={ function () { | |
| onEscapeSpy( 2 ); | |
| wrapper2.unmount(); | |
| } } | |
| /> | |
| ); | |
| simulateEscapeKeydown(); | |
| expect( onEscapeSpy ).toHaveBeenCalledWith( 2 ); | |
| expect( onEscapeSpy ).not.toHaveBeenCalledWith( 1 ); | |
| simulateEscapeKeydown(); | |
| expect( onEscapeSpy ).toHaveBeenCalledWith( 1 ); | |
| } ); | |
| } ); | |
| } ); | |