Download react-use/tests/useMount.test.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 811 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/tests/useMount.test.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-use/tests/useMount.test.ts
-
curl -L -o useMount.test.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/tests/useMount.test.ts
811 Bytes
| import { renderHook } from '@testing-library/react-hooks'; | |
| import { useMount } from '../src'; | |
| const mockCallback = jest.fn(); | |
| afterEach(() => { | |
| jest.resetAllMocks(); | |
| }); | |
| it('should call provided callback on mount', () => { | |
| renderHook(() => useMount(mockCallback)); | |
| expect(mockCallback).toHaveBeenCalledTimes(1); | |
| }); | |
| it('should not call provided callback on unmount', () => { | |
| const { unmount } = renderHook(() => useMount(mockCallback)); | |
| expect(mockCallback).toHaveBeenCalledTimes(1); | |
| unmount(); | |
| expect(mockCallback).toHaveBeenCalledTimes(1); | |
| }); | |
| it('should not call provided callback on rerender', () => { | |
| const { rerender } = renderHook(() => useMount(mockCallback)); | |
| expect(mockCallback).toHaveBeenCalledTimes(1); | |
| rerender(); | |
| expect(mockCallback).toHaveBeenCalledTimes(1); | |
| }); | |