1
我試圖按輸入框。但是,手動觸發事件偵聽器時,嘗試使用酶時,不會觸發事件偵聽器。我在這裏做錯了什麼?酶wrapper.find(..)。模擬按鍵不觸發事件監聽器
事件監聽器
this.input.addEventListener('keypress', function(event){
debugger;
onEnter(event);
});
酶
function setup(store, props) {
return mount(<Provider store={store}>
<component{...props}/>
</Provider>
);
}
beforeEach(() => {
wrapper = setup(store, {});
searchBar = wrapper.find('searchBar');
searchInput = searchBar.find("input");
});
it("when enter is pressed, event should be triggered",()=> {
let wait = false;
runs(()=> {
searchInput.simulate('change', {target: {value: 'helloWorld'}});
searchInput.simulate('keyPress', {which: 13});
setTimeout(()=> {
wait = true;
}, 1000);
})
waitsFor(()=> {
return wait;
}, "", 1500);
})