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

blog idea: why do we do userEvent.click? why not just call the dom's click? #165

Open
hrgui opened this issue Sep 5, 2022 · 0 comments
Open

Comments

@hrgui
Copy link
Owner

hrgui commented Sep 5, 2022

it("should render the menu when the preliminary state is open", async () => {
  renderWithAppProvider(<AppDrawer />, {
    props: { store: setupStore({ ui: { drawerOpen: true } }) },
  });
  expect(screen.getByText(/Home/)).toBeVisible();
  const browseBtn = screen.getByText(/Browse/);
  expect(browseBtn).toBeVisible();
  browseBtn.click();
});

produces the following error

Warning: An update to AppDrawer 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://reactjs.org/link/wrap-tests-with-act
    at AppDrawer (/Users/hrgui/projects/catsroll-tv/src/components/app/AppDrawer.tsx:32:29)
    at QueryClientProvider (/Users/hrgui/projects/catsroll-tv/node_modules/@tanstack/react-query/build/cjs/react-query/src/QueryClientProvider.js:74:3)
    at Provider (/Users/hrgui/projects/catsroll-tv/node_modules/react-redux/lib/components/Provider.js:19:3)
    at AppProvider (/Users/hrgui/projects/catsroll-tv/src/AppProvider.tsx:18:3)
    at Router (/Users/hrgui/projects/catsroll-tv/node_modules/react-router/umd/react-router.development.js:821:17)
    at MemoryRouter (/Users/hrgui/projects/catsroll-tv/node_modules/react-router/umd/react-router.development.js:734:7)
Warning: An update to MemoryRouter 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://reactjs.org/link/wrap-tests-with-act
    at MemoryRouter (/Users/hrgui/projects/catsroll-tv/node_modules/react-router/umd/react-router.development.js:734:7)
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