vendredi 30 octobre 2020

tests working correctly but throwing error testing-library in React

Warning: An update to Form inside a test was not wrapped in act(...).

test('should watch input correctly', async () => {
  const { container } = render(<Form />);
  const password = container.querySelector("input[name='password']");
  const repeatPassword = container.querySelector(
    "input[name='repeatPassword']",
  );

  await act(async () => {
    fireEvent.input(password, {
      target: {
        value: 'Test2020.1',
      },
    });
  });

  await act(async () => {
    fireEvent.input(repeatPassword, {
      target: {
        value: 'Test2020.1',
      },
    });
  });

  expect(password.value).toEqual('Test2020.1');
  expect(repeatPassword.value).toEqual('Test2020.1');
});

I been reading a lot at this known issue but I cant find a solution. Im using react-hook-form to take the values.

Aucun commentaire:

Enregistrer un commentaire