Stub in JavaScript
function getCharacters(callback) {
$.get('http://api.example.com/characters', callback);
}
RvDev
function getCharacters(callback) {
$.get('http://api.example.com/characters', callback);
}
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();
});
});