我正在尝试使用mocha和mongoose编写测试用例。但是我写的以下代码片段给了我错误" Todo"在每个"之前。钩: 错误:超过2000毫秒的超时。确保在此测试中调用done()回调。"我无法解决这个问题。我是节点的初学者。任何人都可以帮我解决这个问题。提前致谢。
var Todo = require('../models/Todo'),
should = require('Should');
describe('Todo', function(){
beforeEach(function(done){
faketodo = {
name : 'xyz',
completed : true,
note : "This is test note"
}
Todo.remove(done);
});
describe('#save()', function(){
var todo;
beforeEach(function(done){
console.log('before each todo entry');
todo = new Todo(faketodo);
console.log('before each todo exit');
done();
});
it('should have name property', function(done){
todo.save(function(err, todo){
should.not.exist(err);
todo.should.have.property('name', 'xyz');
done();
});
});
it('should not save if name is not present', function(done){
todo.name = '';
todo.save(function(err, todo){
should.exist(err);
should.not.exist(todo.name);
done();
});
});
});
});
答案 0 :(得分:-1)
我不确定你为什么要做Todo.remove(已完成);如果你不打算回电话,为什么还要放在首位?
我会尝试改变:
Todo.remove(done);
于:done();
希望有所帮助。