用摩卡测试时超时

Timeout while testing with mocha

本文关键字:超时 测试 摩卡      更新时间:2023-09-26

我正在尝试使用摩卡和猫鼬写一个测试用例。但是下面的代码片段,我写了给我的错误"Todo"之前每个"钩子:错误:超时时间超过2000ms。确保在这个测试中调用了done()回调。"我找不到问题。我是node的初学者。有人能在这个问题上帮助我吗?提前感谢。

 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();
          });
        });
      });
    });

我不知道你为什么要做Todo.remove(done);如果你不打算收回它,为什么要把它放在首位?

我会尝试改变:Todo.remove(done);

to: done();

希望对你有帮助。