Closed Cassiano-Esparta closed 2 years ago
hello, @Cassiano-Esparta I had experienced this warning before. But I can not remember what was the situation though my guess is about something async behavior. As I can see yupResolver async function is defined https://github.com/react-hook-form/resolvers/blob/72aa95c25b0a14f78822cee32517120d6ede4cde/yup/src/yup.ts#L38.
So Can you please provide me with a sample project? I want to dive deep into this warning. Thanks
Yes I think @guvenkaranfil is right, the issue here seems to be that you trigger your handleSubmit function which is asynchronous and it probably updates some states after some promises are resolved, the issue being here that you don't wait in your test for this state update because you're only testing the fact that keyboard dismiss has been called.
First, I'd avise against wrapping your whole test in waitFor because we don't know anymore when we are waiting or not and I'm not sure having events fired within a waitFor is a good pattern because you're not actually waiting for them and do not want them to repeat should your assertions fail. I'd recommend putting only one assertions in each waitfor and keeping events out of it.
To fix the warning, you can either mock the function that is called on your form submit so that it isn't asynchronous but it's not the best here i think, otherwise you should await for something that will be true only once your form will be submitted, for instance that your loader is not visible anymore. The warning says that
Warning: An update to Addresses inside a test was not wrapped in act(...).
So I guess Addresses is one of your component and it has a state which is updated after promises are resolved, so if there is a visual way to see it that's what you should expect in your test, like
fireEvent.press(getByTestId('ZipcodeButton'));
await waitFor(() => {
// expect something on adresses, for instance query a text
}
expect(dismisMock).toHaveBeenCalled();
A way to remember how to fix this warning is when you trigger an event, you can ask yourself how would the user tell if the action is complete (in our case the form submit) and assert on that when possible
Hope it helps !
You can also try
await act(async () => {
fireEvent.changeText(getByTestId('InputZipcode'), {
target: { value: '78556142' },
});
})
@pierrezimmermannbam explained well the overall problem, and I do not believe the problem results from an issue with the library. If you still can't fix it, please post a minimal repro so we can try to figure out what's happening, because I don't think we can do more to help you now.
Meanwhile, I'll close the issue since I believe it was answered. I'll reopen if needed.
Hi, I am having a problem with
act
...I am trying to test a hook-form submit, and when I click my button with
fireEvent
throws a giant error on console...My test:
My code:
Error:
Versions: "@testing-library/jest-native": "^4.0.1", "@testing-library/react-native": "^7.2.0", "jest": "^26.6.3", "jest-expo": "^42.1.0", "react-test-renderer": "17.0.2", "react-hook-form": "^7.9.0", "react-native": "0.63.4",
jest.config.js
(if needed)I've tried to use the
act
function, but not seems to work in my case... I'm forgetting something? Or doing something wrong?I've tried to do as this issue but nothing worked...