Download react-hook-form/src/__tests__/useForm/unregister.test.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.35 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-hook-form/src/__tests__/useForm/unregister.test.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-hook-form/src/__tests__/useForm/unregister.test.tsx
-
curl -L -o unregister.test.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-hook-form/src/__tests__/useForm/unregister.test.tsx
1.35 kB
| import { act, renderHook } from '@testing-library/react'; | |
| import { useForm } from '../../useForm'; | |
| describe('unregister', () => { | |
| it('should unregister an registered item', async () => { | |
| const { result } = renderHook(() => useForm<{ input: string }>()); | |
| result.current.register('input'); | |
| await act(async () => { | |
| await result.current.unregister('input'); | |
| }); | |
| expect(result.current.getValues()).toEqual({}); | |
| }); | |
| it('should unregister an registered item with array name', async () => { | |
| const { result } = renderHook(() => | |
| useForm<{ | |
| input: string; | |
| input2: string; | |
| }>(), | |
| ); | |
| result.current.register('input'); | |
| result.current.register('input'); | |
| result.current.register('input2'); | |
| await act(async () => { | |
| await result.current.unregister(['input', 'input2']); | |
| }); | |
| expect(result.current.getValues()).toEqual({}); | |
| }); | |
| it('should unregister all inputs', async () => { | |
| const { result } = renderHook(() => | |
| useForm<{ | |
| input: string; | |
| input2: string; | |
| }>(), | |
| ); | |
| result.current.register('input'); | |
| result.current.register('input'); | |
| result.current.register('input2'); | |
| await act(async () => { | |
| await result.current.unregister(); | |
| }); | |
| expect(result.current.getValues()).toEqual({}); | |
| }); | |
| }); | |