Download react-use/tests/useError.test.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 548 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/tests/useError.test.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/tests/useError.test.ts
-
curl -L -o useError.test.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/tests/useError.test.ts
548 Bytes
| import { renderHook, act } from '@testing-library/react-hooks'; | |
| import { useError } from '../src'; | |
| const setup = () => renderHook(() => useError()); | |
| beforeEach(() => { | |
| jest.spyOn(console, 'error').mockImplementation(() => {}); | |
| }); | |
| afterEach(() => { | |
| jest.clearAllMocks(); | |
| }); | |
| it('should throw an error on error dispatch', () => { | |
| const errorStr = 'some_error'; | |
| try { | |
| const { result } = setup(); | |
| act(() => { | |
| result.current(new Error(errorStr)); | |
| }); | |
| } catch (err) { | |
| expect(err.message).toEqual(errorStr); | |
| } | |
| }); | |