question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react-select-event results in very long-running tests

See original GitHub issue

First 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:open
  • Created 2 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Pegase745commented, Aug 26, 2021

We’re experiencing the same behavior on our test suites 😕

0reactions
lukemoralescommented, Aug 27, 2021

@Pegase745 Hello! That’s exactly the problem I bumped into. For me, it looks that somehow the testing library’s configure call gets ignored (overwritten?). I had the following code in my runner.js file:

import { configure } from "@testing-library/dom"; 
configure({ testIdAttribute: "data-test" })

After installing react-select-event, the testing library starts using the default test id attribute: data-testid, and this, in turn, results in multiple fails like the following:

TestingLibraryElementError: Unable to find an element by: [data-testid="switch-label"]

Hope this helps to identify the underlying issue. Cheers!

@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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found