【发布时间】:2013-12-10 05:54:08
【问题描述】:
我正在使用 mocha 测试我的 NodeJS 应用程序,并且应该。虽然第一个测试运行顺利,但第二个测试失败(错误等于 null)。在这两个测试中,如果在回调中获得了有效用户(两者在 mongoose 中具有相同的 id)。测试显然不会等待数据库操作发生。
describe("User", function(){
before(function (done) {
// clear database
model.UserModel.collection.remove(done);
})
it("should save", function(done){
user1.save(function(error, user){
should.not.exist(error);
user.should.have.property("first_name", "Rainer");
done();
})
})
it("should not save duplicate user", function(done){
user1.save(function(error, user){
should.exist(error);
done();
})
})
})
当我将第二个测试放在第一个测试的回调中时,它也不起作用。
我想测试重复键错误,但在给定的情况下无法实现。
【问题讨论】:
标签: javascript node.js mongoose mocha.js should.js