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.
Changing Jest preset from "react-native"
to "@testing-library/react-native"
solved the problem.