Skip to content

Instantly share code, notes, and snippets.

@grauwoelfchen
Created November 14, 2013 17:15
Show Gist options
  • Save grauwoelfchen/7470600 to your computer and use it in GitHub Desktop.
Save grauwoelfchen/7470600 to your computer and use it in GitHub Desktop.
stub with `yields`
describe("/api/foo/:id", function() {
before(function() {
var user = { foo: function() {} };
var query = { complete: function() {} };
var foo = "ok";
// stub with yields
sinon.stub(query, "complete").yields(null, foo);
sinon.stub(user, "foo").withArgs("1").returns(query);
login(user);
});
after(function() {
logout();
});
it("should respond with /api/foo/1.json", function(done) {
request(app).get("/api/foo/1.json").set("Authorization", "Bearer " + token)
.expect("Content-Type", "application/json")
.expect(200)
.end(function(error, result) {
if (error) { return done(error); }
done();
});
});
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment