I'm trying to do a simple test of my mongoose model with mocha and chai
// Mock user
var testUser = new User({
companyID: "1",
username: "mockUser",
password: "password",
email: "[email protected]",
});
// Create new user
it('Should add a new user with a hashed password to DB' , (done) => {
User.addUser(testUser, (err, user) => {
if(err) console.log(err);
else {
assert.typeOf(user, 'Object');
assert.equal(user.username, "mockUser");
expect(user.password).to.not.equal("password");
}
done();
});
});
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves
I assume mocha changed since this has been working with previous projects. What am i missing here ?
the model method:
module.exports.addUser = function(newUser, callback) {
bcrypt.genSalt(10, (err, salt) => {
bcrypt.hash(newUser.password, salt, (err, hash) => {
if (err) throw err;
newUser.password = hash;
newUser.save(callback);
});
});
}