摩卡测试运行两次

时间:2014-08-07 13:58:21

标签: node.js mocha

我想弄清楚为什么这个测试运行两次:

it ( "should verify file exists with a one name filename ", function ( done ){   
    var fileNameOneChar = "/Users/myusername/t.mp3"; 
    console.log(" the file path ", fileNameOneChar ); 
    expect( myApi.fileExists( fileNameOneChar ) ).to.be( true ); 
    done();
});

测试连续两次运行(虽然它只定义了一次)第一次通过(这没关系,该文件实际存在并且api工作正常),第二次失败并出现错误:错误:超过5000毫秒超时“。

为什么测试运行两次?我现在已经看了很久以前的时间错误了一段时间,还没有在摩卡上找到任何东西。

1 个答案:

答案 0 :(得分:4)

几分钟前我发生了同样的情况,我发现了一种解决方法(不是修复):在同步模式下运行测试。

基本上,您需要避免设置 it 方法

的done参数

下面是我的测试现在的样子

describe('API /users Endpoint', function () {
  it('GET /users should return a JSON list of users', function (done) {
    request
      .get(config.api.prefix+'users')
      .set('bearer',config.api.key)
      .end(function(err,res){
        if (err) {
          return done(err);
        }
        res.statusCode.should.equal(200);
        res.body.should.not.be(null);
        res.body.posts.should.not.be(undefined);
        res.body.posts.should.not.have.length(0);
      });
  });

希望它有所帮助!

相关问题