I'm trying to test a click on a react component uszing Enzyme + Sinon
var stub = sinon.stub(Comp.prototype, 'save', function() { });
let wrapper = shallow(
<Comp/>
);
wrapper.find('.btn-header').simulate('click');
sinon.assert.called(stub);
Comp.prototype.refineOnClick.restore();
My Comp component has a save function that throws an exception
save: function () {
throw('error');
}
When I run the test, I expect no errors to be thrown and the empty function in the stub to fire - but it doesn't. The actual function inside the component is fired and not the empty stub.
savefunction? As in, does it throw an error but it doesn't call the stub? - ZekeDroidsaveViaAjax. So you'd really want to stubsaveViaAjax, andsaveViaAjaxis what you would pass into your component. Your component'ssavewould callsaveViaAjax. - Tyler Collier