3

I am trying to write a test case using mocha and mongoose. But the following snippet of code that i have written gives me the error "Todo "before each" hook: Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test." I am unable to fing the issue. I am a beginner in node. can anyone please help me out on this issue. Thanks in advance.

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

    });
Dheeraj
  • 546
  • 2
  • 7
  • 19
  • The error says that you need to call the `done()` callback in your test. `Todo.remove(done);` maybe call done first or after?.. – Sebastian Nette Jul 14 '15 at 09:58
  • @SebastianNette yes, but even after calling the done() after Todo.remove(done), I am again getting the timeout. – Dheeraj Jul 14 '15 at 10:13
  • The only problem I see with your code is that you should be doing `Todo.remove({}, done)` as explained on the answers to the question against which I closed yours. – Louis Jan 19 '17 at 21:50

1 Answers1

-1

I'm not sure why you're trying to do Todo.remove(done); why have it in the first place if you're not going to call it back?

I would try changing: Todo.remove(done);

to:done();

Hope that helps.

Rubicon
  • 137
  • 7