Download react-use/tests/misc/hookState.test.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/tests/misc/hookState.test.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-use/tests/misc/hookState.test.ts
-
curl -L -o hookState.test.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/tests/misc/hookState.test.ts
1.03 kB
| import { resolveHookState } from '../../src/misc/hookState'; | |
| describe('resolveHookState', () => { | |
| it('should defined', () => { | |
| expect(resolveHookState).toBeDefined(); | |
| }); | |
| it(`should return value as is if it's not a function`, () => { | |
| expect(resolveHookState(1)).toBe(1); | |
| expect(resolveHookState('HI!')).toBe('HI!'); | |
| expect(resolveHookState(undefined)).toBe(undefined); | |
| }); | |
| it('should call passed function', () => { | |
| const spy = jest.fn(); | |
| resolveHookState(spy); | |
| expect(spy).toHaveBeenCalled(); | |
| }); | |
| it('should pass 2nd parameter to function if it awaited', () => { | |
| const spy = jest.fn((n: number) => n); | |
| resolveHookState(spy, 123); | |
| expect(spy).toHaveBeenCalled(); | |
| expect(spy.mock.calls[0][0]).toBe(123); | |
| }); | |
| it('should not pass 2nd parameter to function if it not awaited', () => { | |
| const spy = jest.fn(() => {}); | |
| /* @ts-expect-error */ | |
| resolveHookState(spy, 123); | |
| expect(spy).toHaveBeenCalled(); | |
| expect(spy.mock.calls[0].length).toBe(0); | |
| }); | |
| }); | |