任何人都可以帮助我测试酶中的input.focus()。我正在写剧本与react.My代码如下。在酶中测试input.focus()
public inputBox: any;
componentDidUpdate =() => {
setTimeout(() => {
this.inputBox.focus();
}, 200);
}
render() {
return (
<div>
<input
type = 'number'
ref = {element => this.inputBox = element } />
</div>
);
}
'eventStub()'从哪里来? –
'eventStub'是任何能够让你的测试通过的东西。在这个例子中,你可以假定组件'FocusingInput'正在监听'mouseEnter'事件,并且当这个事件被触发时('wrapper.simulate('mouseEnter',...)'这么做)事件处理器可以对事件执行一些操作像'preventDefault'。为了使这个工作,你需要准备事件存根来处理这个操作,并发送这个存根作为'simulate'的第二个参数。以下是我的[活动存根](https://gist.github.com/mckomo/128bdb43434749ca1a2299d456ed7d7c)的示例。 – mckomo