Created
March 21, 2013 11:05
-
-
Save maldo/5212253 to your computer and use it in GitHub Desktop.
Example of mocha testing for https://github.com/justin-john/node-user-management/blob/master/routes/users.js#L107-L146, you can add more testing in error conditions
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 should = require('chai').should(); | |
var superagent = require('superagent'); | |
var agent; | |
describe('testing user', function(){ | |
before(function (done) { | |
agent = superagent.agent(); | |
// some other operation you need | |
// like drop your collection for testing o adding something | |
}); | |
it('should not register a user with a weak password', function (done){ | |
agent | |
.post(route.signup) | |
.send({username: 'This is a valid name'}) | |
.send({email : 'my@example.com'}) | |
.send({pwd : ''}) | |
.end(function (req, res) { | |
res.should.have.property('text').that.contain('The password can\'t be empty and 6 - 16 characters required'); | |
done(); | |
}); | |
}); | |
it('registers a new user', function (done) { | |
agent | |
.post(route.signup) | |
.send({username: 'My_name'}) | |
.send({email : 'my@example.com'}) | |
.send({pwd : '123456a'}) | |
.end(function (req, res) { | |
res.should.have.property('statusCode').that.equals(200); | |
res.should.have.property('text').that.contain(username); | |
done(); | |
}); | |
}); | |
it('fails to register a new user with a registered email', function (done) { | |
agent | |
.post(route.signup) | |
.send({username: 'My_name'}) | |
.send({email : 'my@example.com'}) | |
.send({pwd : '123456a'}) | |
.end(function (req, res) { | |
res.should.have.property('statusCode').that.equals(200); | |
res.should.have.property('text').that.contain('This email is already taken!'); | |
done(); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment