Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
react-select-event doesn't trigger the onChange function to set the value during testing

It's been a couple of days that I'm struggling with a test I'm trying to write and thought this would be a good place to ask for some tips. I'm trying to fill a form that uses react-select dropdowns, and these forms are inside a map that renders 4 of them. However when trying to run the code below on the selectors of each form in a loop, after the first iteration which runs fine, the input element found in the form to perform the onChange doesn't have the onChange handler and doesn't trigger the change function to select the option I need. The package I am using for the selection is react-select-event as per the documentation here. I am still a beginner with react-testing-library and testing in general so it's quite probable that I missed something. Any tips or ideas are welcome! Thank you ๐Ÿ™‚

const selectOptionAndAssertValue = async (indicator, field, element, option, inputForm) => {
  await selectEvent.select(element, option.label, {
    container: document.body,
  });

  await waitFor(
    async () => {
      expect(inputForm).toHaveFormValues({
        [${indicator.short_alias}-${field}]: option.value,
      });
    },
    {
      onTimeout: error => console.log(error),
    }
  );
};

Note: to find the inputForm, I am using findByLabelText and it does find the element.


EDIT: Issue replicated in this repo https://github.com/ildaballiu/select-testing-demo


about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

The issue was solved by changing the container to

 container: () => document.body.querySelector('[class$=-menu]')
about 4 years ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!