Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Convert tests from expresso to mocha.

Put test dependencies in the devDependencies in package.json, and add the npm script to run the tests.
  • Loading branch information...
commit 5b6b200b782e7d97b94091d0de1db4e4e41fb1f7 1 parent 3f180ab
@justinlatimer justinlatimer authored
Showing with 24 additions and 18 deletions.
  1. +2 −5 Makefile
  2. +6 −1 package.json
  3. +16 −12 test/authplugin.test.js
View
7 Makefile
@@ -1,7 +1,4 @@
test:
- @expresso test/authplugin.test.js
+ @node_modules/.bin/mocha
-test-cov:
- @TESTFLAGS=--cov $(MAKE) test
-
-.PHONY: test test-cov
+.PHONY: test
View
7 package.json
@@ -20,7 +20,12 @@
},
"devDependencies": {
"express": ">=2.3.2",
- "jade": ">=0.12.1"
+ "jade": ">=0.12.1",
+ "mocha": ">=0.10.1",
+ "should": ">=0.5.1"
+ },
+ "scripts": {
+ "test": "make"
},
"engines": {
"node": ">=0.4.0"
View
28 test/authplugin.test.js
@@ -11,8 +11,8 @@ UserSchema.plugin(authPlugin, {
mongoose.model('User', UserSchema);
User = mongoose.model('User');
-module.exports = {
- "setting a user's password should generate a salt and set a hash": function () {
+describe('User', function () {
+ it('should generate a salt and set a hash when password is set', function () {
var user = new User();
should.strictEqual(undefined, user.salt);
should.strictEqual(undefined, user.hash);
@@ -20,17 +20,21 @@ module.exports = {
user.password.should.equal('hello');
user.salt.should.not.be.undefined;
user.hash.should.not.be.undefined;
- },
-
- 'a user should authenticate with a correct password': function () {
+ });
+ it('should authenticate with a correct password', function (done) {
var user = new User();
user.password = 'hello';
- user.authenticate('hello').should.be.true;
- },
-
- 'a user should fail authentication with an incorrect password': function () {
+ user.authenticate('hello', function (err, matched) {
+ matched.should.be.true;
+ done();
+ });
+ });
+ it('should fail authentication with an incorrect password', function (done) {
var user = new User();
user.password = 'correct';
- user.authenticate('incorrect').should.be.false;
- }
-};
+ user.authenticate('incorrect', function (err, matched) {
+ matched.should.be.false;
+ done();
+ });
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.