简体   繁体   English

react-select-event 不会触发 onChange function 在测试期间设置值

[英]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.我正在尝试填写一个使用react-select下拉列表的表单,这些 forms 位于呈现其中 4 个的 map 内。 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.但是,当尝试在循环中在每个表单的选择器上运行下面的代码时,在第一次运行良好的迭代之后,在表单中找到执行 onChange 的输入元素没有 onChange 处理程序并且不会触发将 function 更改为 select 我需要的选项。 The package I am using for the selection is react-select-event as per the documentation here .根据 此处的文档,我用于选择的 package 是react-select-event I am still a beginner with react-testing-library and testing in general so it's quite probable that I missed something.我仍然是react-testing-library和一般测试的初学者,所以很可能我错过了一些东西。 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.注意:要查找 inputForm,我使用的是 findByLabelText,它确实找到了元素。


EDIT: Issue replicated in this repo https://github.com/ildaballiu/select-testing-demo编辑:此回购https://github.com/ildaballiu/select-testing-demo中复制的问题


The issue was solved by changing the container to该问题已通过将容器更改为

 container: () => document.body.querySelector('[class$=-menu]')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM