Skip to content

Instantly share code, notes, and snippets.

@abrkn abrkn/gist:2864350
Created Jun 3, 2012

Embed
What would you like to do?
Mocha + Sinon + Expect.js
describe('addHandler', function() {
it('parses request and calls api', function() {
var values = {
link: 'link' + Math.floor(Math.random() * 1000),
user: 'user' + Math.floor(Math.random() * 1000),
seconds: Math.floor(Math.random() * 1000)
};
// setup
var impressionsMock = sinon.mock(impressions);
impressionsMock.expects('add', function(db, user, link, facts, callback) {
expect(db).to.be.ok();
expect(user).to.eql(values.user);
expect(link).to.eql(values.link);
expect(facts).to.be.ok();
expect(facts).to.have.property('seconds', values.seconds);
expect(typeof callback).to.be('function');
callback();
});
var res = {
end: sinon.stub()
};
var req = {
session: { user: { _id: values.user } },
body: { link: values.link, seconds: values.seconds }
};
// test
impressions.addHandler(req, res);
// verify
expect(res.end.calledOnce);
impressionsMock.verify();
impressionsMock.restore();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.