任何人都可以幫助我測試酶中的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