Last active
August 29, 2015 14:25
-
-
Save mattcollier/6e2d29ee44bbf9fc2b21 to your computer and use it in GitHub Desktop.
Correct sinon usage?
This file contains 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
'use strict'; | |
var sinon = require('sinon'); | |
var request = require('request'); | |
describe('standalone-issuer', function() { | |
var rPost; | |
beforeEach(function(done) { | |
rPost = sinon.stub(request, 'post'); | |
rPost.withArgs({uri:'somewhere',body:'something'}, sinon.match.any) | |
.yields(null, {statusCode: 200}, JSON.stringify({someData: 'something!'})); | |
rPost.withArgs({uri:'somewhere',body:'somethingElse'}, sinon.match.any) | |
.yields(null, {statusCode: 400}, JSON.stringify({someData: 'something!'})); | |
done(); | |
}); | |
afterEach(function(done) { | |
request.post.restore(); | |
done(); | |
}); | |
it('should return 200', function(done) { | |
request.post({uri:'somewhere',body:'something'}, function(err, res, body) { | |
should.not.exist(err); | |
res.statusCode.should.equal(200); | |
sinon.assert.calledWith(rPost, {uri:'somewhere',body:'something'}, sinon.match.any); | |
done(); | |
}) | |
}); | |
it('should return 400', function(done) { | |
request.post({uri:'somewhere',body:'somethingElse'}, function(err, res, body) { | |
should.not.exist(err); | |
res.statusCode.should.equal(400); | |
sinon.assert.calledWith(rPost, {uri:'somewhere',body:'somethingElse'}, sinon.match.any); | |
done(); | |
}) | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment