React testing library on change for Material UI Select component

material-ui’s select component uses the mouseDown event to trigger the popover menu to appear. If you use fireEvent.mouseDown that should trigger the popover and then you can click your selection within the listbox that appears. see example below. import React from “react”; import { render, fireEvent, within } from “react-testing-library”; import Select from “@material-ui/core/Select”; import … Read more

How to solve the “update was not wrapped in act()” warning in testing-library-react?

Updated answer: Please refer to @mikaelrs comment below. No need for the waitFor or waitForElement. You can just use findBy* selectors which return a promise that can be awaited. e.g await findByTestId(‘list’); Deprecated answer: Use waitForElement is a correct way, from the docs: Wait until the mocked get request promise resolves and the component calls … Read more

Recommended approach for route-based tests within routes of react-router

If you think about the responsibility of the AccessDenied component, it isn’t really to send the user home. That’s the overall behaviour you want, but the component’s role in that is simply to send the user to “/”. At the component unit level, therefore, the test could look something like this: import React, { FC … Read more