I have a project that makes some calls to Twitter's API from the node.js server that I would like to test. However, I don't want to test the Twitter API (OAuth and the actual API I'm calling), so I thought it would be best to stub it out.
I found sinon.js that supports this supposedly. I have not found an example of how to do this and was wondering if this has been done before. And if so, seeing some sample code would really help.
What are you doing to call the API?
Imagine you use a method called api.call('url', function (error, response) {...}):
you can "fake" the callback with sinon, gently or whatever you like.
Example using gently:
gently.expect(api, 'call', function (url, callback) {
assert.equal(url, 'http://api.twitter.com/...');
callback(Error('Fake error'), null);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With