I'm moving over to joke with mocha, and I wonder if there is a way to spy on the response method. For example, let's say I have the following method in my component (Ignore the sdk library, it just constructs a jQuery ajax call):
getData() { sdk.getJSON('/someURL').done(data => { this.setState({data}); }); }
Using sine, I would check this by spying on a prototype, for example:
it('should call getData', () => { sinon.spy(Component.prototype, 'getData'); mount(<Component />); expect(Component.prototype.getData.calledOnce).to.be.true; });
this would ensure that the code is not mocked by this method. Is there any similar functionality as a joke?
EDIT: Also, if this function does not exist, what is the next best strategy for testing API calls?
source share