-
| I have those two tests inside a describe(): describe('SignIn', () => {
  // https://stackoverflow.com/a/52619219/10247962
  const createTestProps = (props: Record<string, any>) => ({
    navigation: {
      navigate: jest.fn(),
    },
    ...props,
  });
  let props: any; // use type "any" to opt-out of type-checking
  beforeEach(() => {
    props = createTestProps({});
    jest.clearAllMocks(); // This doesn't fix my issue
  });
  it('must SignIn using valid no-api test account', async () => {
    const mockFn = jest.fn();
    const email = '[email protected]'; // valid email for test account
    const password = '12345678'; // valid password
    const { getByTestId } = render(<SignIn onSubmit={mockFn}/>);
    await fireEvent.changeText(getByTestId('signin_email'), email);
    await fireEvent.changeText(getByTestId('signin_password'), password);
    await act(async () => { await fireEvent.press(getByTestId('signin_submit'));}); // Required for some strange reason, error without it.
    expect(mockFn).toBeCalledWith({ email, password });
  });
  it('must complain about invalid SignInScreen using no-api account but with wrong password', async () => {
    const email = '[email protected]';
    const password = 'wrongpassword';
    const { getByTestId, getByText } = render(<SignInScreen {...props}/>);
    await fireEvent.changeText(getByTestId('signin_email'), email);
    await fireEvent.changeText(getByTestId('signin_password'), password);
    await act(async () => { await fireEvent.press(getByTestId('signin_submit')); });
    expect(getByText('Usuário e/ou senha inválidos')).toBeTruthy();
  });
});(yeah, for some reason those await and act were necessary, textinputs wouldn't be filled or errors without them) Test: The onSubmit is not retuning a Promise as it should, but here what is causing it: The first test. The mock is replacing the onSubmit on the second test for some very strange reason. The onSubmit is a prop that is passed from SignInScreen to SignIn. If I comment the first test, the second one works fine. WHY this is happening??? How can I fix it? | 
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
| Actually, I am stupid lol The error is being raised on the first test, not the second one. As jest.fn() isn't a promise, there isn't a catch prop. | 
Beta Was this translation helpful? Give feedback.
Actually, I am stupid lol
The error is being raised on the first test, not the second one. As jest.fn() isn't a promise, there isn't a catch prop.