【发布时间】:2019-04-16 19:14:11
【问题描述】:
每当我尝试模拟传递event 对象的事件时,我都会得到this 是undefined。
const onBlur = sinon.spy(Input.prototype.handleBlur);
const wrapper = shallow(<Input handleBlur={onBlur} />);
//...
wrapper.find('input').simulate('blur', { target: {value: ''} });
在handleBlur 方法内部,this 是未定义的。但是,如果我决定不模拟 event 对象,则事件未定义。
另外,我尝试使用 mount 代替:
const wrapper = shallow(<Input handleBlur={onBlur} />);
但是,这是同一回事。但是,在更新 npm 库之前,我什至无法达到这一点。
【问题讨论】:
标签: javascript reactjs unit-testing sinon enzyme