Reputation: 175
Whenever I try to simulate an event where I am passing the event
object, I am getting that this
is undefined
.
const onBlur = sinon.spy(Input.prototype.handleBlur);
const wrapper = shallow(<Input handleBlur={onBlur} />);
//...
wrapper.find('input').simulate('blur', { target: {value: ''} });
Inside of the handleBlur
method, this
is undefined. However, if I decide not to mock the event
object, then event is undefined.
Also, I tried using mount
instead:
const wrapper = shallow(<Input handleBlur={onBlur} />);
But, it's the same thing. However, I couldn't even get to that point until I updated the npm libraries.
Upvotes: 1
Views: 275
Reputation: 19
try using
const onBlur = sinon.spy(Input.prototype, "handleBlur");
instead
const onBlur = sinon.spy(Input.prototype.handleBlur);
Upvotes: 1