Search code examples
javascriptreactjsreact-nativejestjsreact-native-testing-library

React Native Testing Library shows a warning for using `waitFor`


I have this test with Jest and react-native-testing-library

it('submits form on submit button press', async () => {
  const onSubmit = jest.fn();
  const values = { username: 'jack' };
  const { getByRole } = render(
    <Form initialValues={values} onSubmit={onSubmit} />,
  );

  const button = getByRole('button');

  fireEvent.press(button);

  await waitFor(() => {
    expect(onSubmit).toBeCalledWith(values, expect.anything());
  });
});

It passes, but it throws this warning

Warning: You seem to have overlapping act() calls, this is not supported. Be sure to await previous act() calls before making a new one.

NOTE: if I remove waitFor the warning goes aways but the test fails because it doesn't call the onSubmit function immediatly.


Solution

  • Changing Jest preset from "react-native" to "@testing-library/react-native" solved the problem.