Skip to content

Instantly share code, notes, and snippets.

@Zenedith
Created June 30, 2012 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zenedith/3024952 to your computer and use it in GitHub Desktop.
Save Zenedith/3024952 to your computer and use it in GitHub Desktop.
expresso -> mocha
var
app = require(__dirname + '/../app'),
exports.testGetSessionValid = function (beforeExit, assert) {
assert.response(app, {
url: '/api/getSession/apikey',
method: 'GET',
headers: { 'Content-Type': 'text/html; charset=utf-8' }
}, {
status: 200,
headers: { 'Content-Type': 'application/json; charset=utf-8' }
},
function(res) {
var json = JSON.parse(res.body);
assert.isDefined(json.sess);
assert.equal(json.userId, 0);
}
);
};
#!/bin/bash
# Mocha tests starter
mocha -R list -u exports test/mochaSession.js
exit 0
var
app = require(__dirname + '/../app'),
supertest = require('supertest'),
should = require('should');
exports.testGetSessionValid = {
'GET /api/getSession/:apikey': {
'should return valid json response with sess and userId property': function (done){
supertest(app)
.get('/api/getSession/apikey')
.expect('Content-Type', 'application/json; charset=utf-8')
.expect(200)
.end(function (err, res) {
if (err) {
done(err);
}
try {
res.body.should.have.property('sess');
res.body.should.have.property('userId');
res.body.userId.should.equal(0);
done();
}
catch (e) {
done(e);
}
});
}
}
};
@Zenedith
Copy link
Author

Gist shows how to fast switch from expresso to mocha "response" testing (expressoSession.js -> mochaSession.js)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment