Skip to content

Commit

Permalink
馃悶 fix #9521 isValidting property stuck
Browse files Browse the repository at this point in the history
  • Loading branch information
bluebill1049 committed Dec 5, 2022
1 parent c7210f1 commit 7350caf
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
51 changes: 51 additions & 0 deletions src/__tests__/useFormState.test.tsx
Expand Up @@ -118,6 +118,57 @@ describe('useFormState', () => {
expect(count).toEqual(1);
});

it('should update isValidating correctly', async () => {
function Child() {
const { isDirty, isValid, isValidating } = useFormState();
const enabled = !isValidating && isDirty && isValid;

return (
<button disabled={!enabled} type="submit">
Submit
</button>
);
}

function App() {
const formFunctions = useForm({
mode: 'onChange',
});
const { register } = formFunctions;

return (
<FormProvider {...formFunctions}>
<form>
<input {...register('value', { required: true })} />
<Child />
</form>
</FormProvider>
);
}

render(<App />);

fireEvent.change(screen.getByRole('textbox'), {
target: {
value: '1',
},
});

await waitFor(() => {
expect(screen.getByRole('button')).not.toBeDisabled();
});

fireEvent.change(screen.getByRole('textbox'), {
target: {
value: '12',
},
});

await waitFor(() => {
expect(screen.getByRole('button')).not.toBeDisabled();
});
});

it('should update formState separately with useFormState', async () => {
let count = 0;
let testCount = 0;
Expand Down
1 change: 0 additions & 1 deletion src/logic/createFormControl.ts
Expand Up @@ -175,7 +175,6 @@ export function createFormControl<

const _updateIsValidating = (value: boolean) =>
_proxyFormState.isValidating &&
value !== _formState.isValidating &&
_subjects.state.next({
isValidating: value,
});
Expand Down

0 comments on commit 7350caf

Please sign in to comment.