Closed SocialBrothersDEV closed 4 years ago
same problem here.
Any progress/update on this? Its currently preventing me to properly write tests for like 70% of my components..
Hi @SocialBrothersDEV!
My guess is that this is related to https://github.com/jaredpalmer/formik/issues/1543. I believe these Formik callbacks are asynchronous. Have you tried wrapping your blur fireEvent in async act ala https://github.com/jaredpalmer/formik/issues/1543#issuecomment-547501926?
If that doesn't work, a repository that reproduces the error will help me debug this.
This is not really an issue. It is happening because you are probably updating the state on blur but are not telling jest when to resume testing after it changes. This is an example with changeText, just so it's more clear. But it works the same way with blur.
it('changes value ', async() => {
const { queryByTestId } = render(<SomeForm />);
fireEvent.changeText(queryByTestId('example'), 'hello');
await wait(() => {
expect(queryByTestId('example').getProp('value')).toBe('hello'); // what state changed, in this case the value of the input
});
});
FYI, this repository is no longer responsible for this package. See the migration guide to v7.0 and check if it happens there as well.
react-native
native-testing-library
version: 5.0.3jest-preset
: @testing-library/react-nativereact-native
version: 0.61.5node
version: 10.16.0Relevant code or config:
What you did:
I tried to fireEvent.blur() on an input field.
What happened:
Gives the following error:
Reproduction:
Problem description:
Whenever you fire a blur event on a textinput field, you'll get an error message by Formik (i think):
Warning: An update to Formik inside a test was not wrapped in act(...). When testing, code that causes React state updates should be wrapped into act(...):
When i manually wrap the blur() in an act(), it still gives me the same error message. The other fireEvent functions im using are functioning as expected, except this one.
Suggested solution:
It has something to do with the act(). Docs state it should be applied automatically to all fireEvent functions, but im getting this error message. Even if i manually wrap it with act().