挂钩未正确执行前的摩卡

时间:2014-03-03 01:43:02

标签: node.js express mocha

我在ExpressJS应用上设置了一个带有Mocha的测试套件。在测试中,我想在套件运行之前删除集合中的所有模型,并且我正在执行以下操作:

var Users = require("../models/Users").model;

before(function(done){
    Users.remove({}, function(){
    console.log("removed");
    done();
});

//rest of the test suite here

麻烦的是,这是在挂钩超时之前。我在这里错过了什么?顺便说一句,如果我把它改成后钩子,结果是一样的 - 它永远不会掉落模型,并且超时。

2 个答案:

答案 0 :(得分:2)

默认情况下,Mocha超时所有测试超过2秒。 试试这个:

var Users = require("../models/Users").model;

this.timeout(5000); //sets timeout to 5 sec

before(function(done){
   Users.remove({}, function(){
   console.log("removed");
   done();
});

答案 1 :(得分:0)

按指定的in the manual禁用超时。