Shi*_*pta 4 reactjs react-testing-library
我正在为我的反应应用程序使用反应测试库。在一个测试用例中,我需要在文本框和焦点中填充一些值。
这是测试脚本 -
it('searchbox wrapper',async()=>{
let wrapper=getSearchBoxWrapperInstance('')
let inputBox=wrapper.findByTestId('inputText');
inputBox.value='12345';
fireEvent(inputBox,'focusOut');
})
Run Code Online (Sandbox Code Playgroud)
当我运行测试用例时,出现以下错误 -
TypeError: element.dispatchEvent is not a function
79 | let inputBox=wrapper.findByTestId('inputText');
80 | inputBox.value='12345';
> 81 | fireEvent(inputBox,'focusOut');
| ^
82 | //fireEvent('Blur',
83 |
84 | //await (() => wrapper.getByText('')))
at fireEvent (node_modules/dom-testing-library/dist/events.js:533:18)
Run Code Online (Sandbox Code Playgroud)
如果我可以提供更多信息,请告诉我
我假设getSearchBoxWrapperInstance返回 的结果render。
尝试一下是否有效:
it('searchbox wrapper',async()=>{
let wrapper=getSearchBoxWrapperInstance('')
let inputBox=wrapper.findByTestId('inputText');
fireEvent.change(inputBox, { target: { value: '12345' } });
fireEvent.focusOut(inputBox);
// In alternative you could try fireEvent.blur
})
Run Code Online (Sandbox Code Playgroud)
也有可能findByTestId找不到您的元素。尝试将其注销以查看是否是这种情况,或者getByTestId如果未找到该元素,则使用哪些错误。
| 归档时间: |
|
| 查看次数: |
18359 次 |
| 最近记录: |