Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use React Testing Library Tutorial: aways act() warning #203

Closed
Joeoeoe opened this issue Jun 15, 2021 · 0 comments
Closed

How to use React Testing Library Tutorial: aways act() warning #203

Joeoeoe opened this issue Jun 15, 2021 · 0 comments

Comments

@Joeoeoe
Copy link

Joeoeoe commented Jun 15, 2021

Hi Robin, I am learning RTL by reading your aritlce How to use React Testing Library Tutorial.

When I write this test example:

import React from 'react';
import { render, screen } from '@testing-library/react';
 
import App from './App';
 
describe('App', () => {
  test('renders App component', async () => {
    render(<App />);
 
    expect(screen.queryByText(/Signed in as/)).toBeNull();
 
    screen.debug();
 
    expect(await screen.findByText(/Signed in as/)).toBeInTheDocument();
 
    screen.debug();
  });
});

There is aways Warning:

    console.error
      Warning: An update to App inside a test was not wrapped in act(...).
      
      When testing, code that causes React state updates should be wrapped into act(...):
      
      act(() => {
        /* fire events that update state */
      });
      /* assert on the output */
      
      This ensures that you're testing the behavior the user would see in the browser. Learn more at https://fb.me/react-wrap-tests-with-act
          in App

I have googled for the reason and solution, but I have added await in the code.

Do you have any solutions please ?

@Joeoeoe Joeoeoe closed this as completed Jul 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant