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);
})