/
githubmirror
/
react-hook-form
Обзор
Документация
Войти
/
githubmirror
/
react-hook-form
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/__tests__/useFormContext.server.test.tsx
57 строк
1 KB
Beier (Bill)
💭 fix React import inconsistency (#10479)
01 июн 2023, 06:29
Не верифицирован
01 июн 2023, 06:29
83f79dd
Код
Авторство
О чём код?
import React from 'react'; import { renderToString } from 'react-dom/server'; import { useController } from '../useController'; import { useForm } from '../useForm'; import { FormProvider, useFormContext } from '../useFormContext'; import { useFormState } from '../useFormState'; import { useWatch } from '../useWatch'; describe('FormProvider', () => { it('should work correctly with Controller, useWatch, useFormState.', () => { const App = () => { const { field } = useController({ name: 'test', defaultValue: '', }); return <input {...field} />; }; const TestWatch = () => { const value = useWatch({ name: 'test', }); return <p>{value}</p>; }; const TestFormState = () => { const { isDirty } = useFormState(); return <div>{isDirty ? 'yes' : 'no'}</div>; }; const TestUseFormContext = () => { const methods = useFormContext(); methods.register('test'); return null; }; const Component = () => { const methods = useForm(); return ( <FormProvider {...methods}> <App /> <TestUseFormContext /> <TestWatch /> <TestFormState /> </FormProvider> ); }; const output = renderToString(<Component />); expect(output).toEqual('<input name="test" value=""/><p></p><div>no</div>'); }); });