Not being able to test onSubmit while using react-hook-form #3394
Unanswered
poojan1296-eng
asked this question in
Q&A
Replies: 2 comments 5 replies
-
|
maybe this is useful: https://react-hook-form.com/advanced-usage#TestingForm |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
For people coming here from search, had this issue multiple times using // do the changes needed in test:
await userEvent.type(screen.getByLabelText('some input to change value'), 'new value');
// this can be needed when just clicking body isn't enough to trigger validation
// await userEvent.click(screen.getByLabelText('some input'));
// click body to blur input and trigger validation:
await userEvent.click(document.body); |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am facing an issue while writing unit test case to check whether the submit function is getting invoked. The issue I am facing is the similar one as that of: https://spectrum.chat/react-hook-form/help/solved-testing-the-onsubmit~364b8d79-c2f2-4d1c-a3ae-d56fed134128
However, the code structure I am using is slightly different in the sense that I am not returning the "form component" directly but instead I am returning the "form component " wrapped inside "FormContext".
**Error I am getting is as follows:
expect(jest.fn()).toHaveBeenCalled()
Beta Was this translation helpful? Give feedback.
All reactions