I created a login process with the MEAN base stack and using a passport for the authentication process.
I am trying to set up a test to make sure the login process is working. To enter the system here, the code I used is used:
it ('login', function(done) { agent.post(config.web.vhost + '/login') .send({ email: ' bruce@wayne.inc ', password: 'batman' }) .end(function(err, res) { if (err) console.log('error' + err.message); res.should.have.status(200); done(); }); });
I get the following error:
no error email: bruce@wayne.inc . No error Error .double callback!
1 passing (2s) 1 failing 1) User login: Uncaught TypeError: Cannot read property 'should' of undefined
I know that my routes and credentials are good, but I can't figure out what doesn't work here. These are my first steps with user testing, so I probably don't understand what is right.
Here is the rest of my test:
var should = require("should"); var mongoose = require('mongoose'); var request = require('superagent'); var agent = request.agent(); var config = require("../settings/conf"); var dbUrl = require("../config/database.js"); var User = require('../server/models/user'); var db; describe('User', function() { before(function(done) { db = mongoose.connect(dbUrl.url); done(); }); after(function(done) { mongoose.connection.close() done(); }); beforeEach(function(done) { var user = new User({ email: ' bruce@wayne.inc ', password: 'batman', firstName: 'Bruce', lastName: 'Wayne' }); user.save(function(err, user) { if (err) console.log('error' + err.message); else console.log('no error'); done(); }); }); it('find a user by username', function(done) { User.findOne({ email: ' bruce@wayne.inc ' }, function(err, user) { user.email.should.eql(' bruce@wayne.inc '); console.log(" email: ", user.email) done(); }); }); it ('login', function(done) { agent.post(config.web.vhost + '/login') .send({ email: ' bruce@wayne.inc ', password: 'batman' }) .end(function(err, res) { if (err) console.log('error' + err.message); res.should.have.status(200); done(); }); }); afterEach(function(done) { User.remove({ email: ' bruce@wayne.inc ' }, function() { done(); }); }); });