Created
June 30, 2012 18:27
-
-
Save Zenedith/3024952 to your computer and use it in GitHub Desktop.
expresso -> mocha
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
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); | |
} | |
); | |
}; |
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
#!/bin/bash | |
# Mocha tests starter | |
mocha -R list -u exports test/mochaSession.js | |
exit 0 |
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
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); | |
} | |
}); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gist shows how to fast switch from expresso to mocha "response" testing (expressoSession.js -> mochaSession.js)