-
Hi, I have a fairly complex form with the latest version that behaves properly in the browser but oddly in tests. <Button
type="submit"
onClick={onSubmit}
disabled={!formState.isDirty || !formState.isValid}
>
Submit
</Button> In the tests, I update a field to make the form valid and then: const submitButton = await screen.findByRole('button', { name: /Submit/i });
await waitFor(() => {
expect(submitButton).toBeEnabled();
}); The odd part is that this fails by default. However if I add the following after the button then the test passes reliably: <div hidden>
{ formState.isValid }
</div> Adjusting the timeout on the Any idea on what's happening or how to diagnose it? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It looks like you don't destruct the |
Beta Was this translation helpful? Give feedback.
It looks like you don't destruct the
isValid
form state before reading it.formState
is aProxy
object - a performance optimisation you can read about in this section.