Tengo esta prueba con Jest y 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()); }); });Pasa, pero tira este aviso
Warning: You seem to have overlapping act() calls, this is not supported. Be sure to await previous act() calls before making a new one. NOTA: si waitFor la advertencia desaparece pero la prueba falla porque no llama a la función onSubmit inmediatamente.
Cambiar el ajuste preestablecido de Jest de "react-native" a "@testing-library/react-native" resolvió el problema.
Trata de cambiar
await waitFor(() => { expect(onSubmit).toBeCalledWith(values, expect.anything()); });a
waitFor(() => { expect(onSubmit).toBeCalledWith(values, expect.anything()); });