Answer the question
In order to leave comments, you need to log in
Why is the save to database function not working in a Mocha test?
I'm writing a test to check if a user is saved to a Mongo database (using Mongoose). I copied the
test code from the documentation :
const User = require('./../models/User');
describe('User', function() {
describe('#save()', function() {
const newUser = {
name: 'TestUser',
password: 'testPassword2',
email: '[email protected]'
};
it('should save without error', function(done) {
const user = new User(newUser);
console.log(user); //1
user.save(function(err) {
console.log('save');
if (err) done(err);
else done();
});
});
});
});
Error: Timeout of 2000ms exceeded. for async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
let user = new User({name, password, email});
user.save((err) => {
if(err) {
res.send('ERROR! ' + JSON.stringify(err));
} else {
res.send('saved!');
}
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question