I am currently engaged in JavaScript unit testing using Mocha and Sinon. My goal is to verify if a specific method is called under certain conditions.
However, I have encountered difficulties purely testing the method call. To clarify, I aim to replace the actual method with a fake one to avoid simulating the entire application state just for this simple test.
This snippet displays my current test code:
it('calls the handleResults method when its model syncs', function () {
var spy = sinon.stub( this.appview, 'handleResults' );
this.appview.model.fetch();
server.requests[0].respond( 200,
{ "Content-Type": "application/json" },
JSON.stringify( [ { id: "casa", text: "Something" } ] )
);
spy.should.have.been.called;
});
The actual this.appview.handleResults
method is executed, but what I desire is to invoke a fake version solely responsible for verifying the method call without any additional actions.
What could be the issue here?