如何解决酶不工作模拟反应组件中的鼠标按下事件
这是我使用draftJS的组件
<button className = { value.includes(1) ? "text-button-style-clicked" :"text-button-style" } onMouseDown = { e => { _onUnderlineClick(e); handleChange(1); } }>U</button>
<button className = { value.includes(2) ? "text-button-style-clicked" :"text-button-style" } onMouseDown = { e => { _onBoldClick(e); handleChange(2);} }>B</button>
const _onBoldClick = (e) => {
e.preventDefault();
onEnterText(RichUtils.toggleInlinestyle(editorState,'BOLD'));
}
const _onUnderlineClick = (e) => {
e.preventDefault();
onEnterText(RichUtils.toggleInlinestyle(editorState,'UNDERLINE'));
const handleChange = (val) => {
if(value.includes(val)){
setValue(value.filter(v=>v!==val))
}else{
setValue([...value,val]);
}
}
这里的模拟似乎不起作用,所以在 onMouseDown 事件之后没有覆盖这个函数调用
it('onmousedown button',async () => {
const spy = jest.spyOn(axios,'get');
spy.mockImplementation(async() => await act(() => Promise.resolve({ data: {data} })));
const component = mount( <Provider store= {store}>
<MyComponent /> </Provider>);
expect(component.find('button')).toHaveLength(7);
expect(component.find('.text-button-style')).toHaveLength(4);
console.log(component.find('.text-button-style').at(0).debug())
expect(component.find('.text-button-style').at(0).simulate('click'));
await component.find('.text-button-style').at(0).invoke('onMouseDown')
await component.find('.text-button-style').at(1).invoke('onMouseDown')
await component.find('.text-button-style').at(2).invoke('onMouseDown')
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。