react-select-event results in very long-running tests
See original GitHub issueFirst of all thank you very much for this library, it simplifies testing with react-select
immensely!
Recently I rewrote many of our old tests using react-select-event
, but noticed that test runtime went up by a factor of 5 or more. On my local machine tests are taking 5-12 seconds to run, on CI servers up to 30 seconds. This adds up quickly!
We’re using formik
and react-select
for both single and multi-select dropdowns.
Here is a distilled example of one such test:
it("submits the correct values", async () => {
const submitStep = jest.fn();
const values = {
name: "ACME corporation",
industries: "Finance",
city: "Berlin",
country: "Deutschland",
postalCode: "10000",
};
render(
<CompanyNameAndIndustry
submitStep={submitStep}
initialValues={{
name: "",
industries: "",
city: "",
country: "",
postalCode: "",
}}
/>
);
userEvent.type(screen.getByLabelText("Name des Unternehmens*"), values.name);
await selectEvent.select(screen.getByLabelText("Branche"), values.industries);
userEvent.type(screen.getByLabelText("Ort*"), values.city);
userEvent.type(screen.getByLabelText("Postleitzahl*"), values.postalCode);
await selectEvent.select(screen.getByLabelText("Land"), values.country);
userEvent.click(screen.getByText("Weiter"));
await waitFor(() => expect(submitStep).toHaveBeenCalledWith(values));
});
When I remove the selectEvent.select()
calls, the runtime goes back down to <1 second.
My questions:
- Is there anything obvious that I’m doing wrong here?
- Is it expected that tests should take drastically longer?
- Is there any way to optimize this?
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
how to test react-select with react-testing-library - Stack Overflow
In my project, I'm using react-testing-library and jest-dom. I ran into same problem - after some investigation I found solution, based on ...
Read more >Optimize your react-select component to smoothly render ...
Optimize your react-select component to smoothly render 10k+ data · 1. Set ignoreAccents to false · 2. Disable onMouseMove and onMouseOver events.
Read more >Test Utilities - React
ReactTestUtils makes it easy to test React components in the testing framework of your choice. At Facebook we use Jest for painless JavaScript...
Read more >Testing-library: avoid these mistakes in async tests
Testing is a crucial part of any large application development. The more code you write, the more... Tagged with react, testing, webdev, ...
Read more >react-select-event - Testing Library
react -select-event is a companion library for React Testing Library that provides helper methods for interacting with react-select elements.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We’re experiencing the same behavior on our test suites 😕
@lukaszwnek I believe that your case is yet another issue to be resolved. With @Pegase745 and I, we use the default
data-testid
field so there’s definitely another issue causing our race condition as Michel said