茉莉花testing用例不从mongo保存返回

我使用https://github.com/mhevery/jasmine-node来testing我的nodejs服务器路由。 我的mongoose模型有一个工作前置function如下

userSchema.pre('save', function(next) { var user = this; if (!user.isModified('password')) return next(); bcrypt.genSalt(10, function(err, salt) { if (err) return next(err); logger.info('Hashing password!!!'); bcrypt.hash(user.password, salt, null, function(err, hash) { if (err) return next(err); user.password = hash; next(); }); }); }); 

现在我需要在jasmine中编写一个testing用例,创build一个userSchema对象并将其保存到mongodb中,以便在testing用例中进一步使用它。

 var User = require("../../../../models/User"); it("{postLogin - invalid}", function(done) { var user = new User({email: "test@test.com", password: "a"}); user.save(function(err) { if (err){ console.log(err); return next(err); } console.log('user saved to db: ' +user.email); request.post(invalidLoginParams, function(error, response, body) { expect(response.statusCode).toBe(400); done(); }); }); },15000); 

我运行上面的testing用例使用茉莉节点,我得到日志“哈希密码!!! 这意味着它正在调用这个函数。 但在此之后,它永远不会返回到我的testing案例。 它应该打印日志'用户保存到DB:'但是它永远不会从.pre('save')函数返回。 任何想法,我在哪里,缺less什么。 在Google上找不到任何答案。 希望能在这里得到它! 谢谢

请确保正确调用callback“done()”。