stub in js code example
Example 1: stub in javascript
describe('getCharacters()', function () {
it('should get the characters from an external API', function () {
const spy = sinon.spy();
const fakedGet = sinon.stub($, 'get');
fakedGet.yields();
getCharacters(spy);
expect(spy.calledOnce).toBeTruthy();
});
});
Example 2: stub in javascript
function getCharacters(callback) {
$.get('http://api.example.com/characters', callback);
}