Created
September 22, 2016 17:10
-
-
Save jonasporto/c3dd601c13d411739fcb96bfb22f8995 to your computer and use it in GitHub Desktop.
example of stub with sinon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// install sinon via npm | |
// npm install sinon --save-dev | |
// require sinon in your test/client_api.js | |
var sinon = require("sinon"); | |
// add this test expectation | |
it("cover error", function (done) { | |
var url = URL_ROOT + "/client"; | |
// stub client, changing return of Client.find | |
stubClient = sinon.stub(Client, 'find', function(obj, callback) { | |
callback(new Error('An Error Has Occurred'), []); | |
}); | |
superagent.get(url) | |
.set("Authorization", token) | |
.end(function (error, res) { | |
// make sure of call restore to avoid, unexpected result for others tests expectation | |
stubClient.restore(); | |
assert.equal(res.status, status.INTERNAL_SERVER_ERROR); | |
done(); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment