为什么在使用chai在mocha中测试时不会抛出错误?

时间:2015-04-14 08:30:22

标签: node.js mocha chai

      foos.forEach(function(foo){
        expect(foo).to.have.ownProperty('stuff');
        expect(foo.stuff).to.exist;
        expect(foo.stuff.url).to.exist;
        expect(foo).to.have.deep.property('stuff.url').to.contain('http://');
      });

      done();

我循环遍历项目列表foos,如果其中一个测试失败,它就不会停止执行,只会挂起。例如,在我的第二次和第三次测试失败但我没有得到任何迹象。我们可以不在内部使用expect进行循环吗?当数据有效时,它似乎工作正常。

1 个答案:

答案 0 :(得分:0)

    doPromise()
        .then(function(foos){
              foos.forEach(function(foo){
                expect(foo).to.have.ownProperty('stuff');
                expect(foo.stuff).to.exist;
                expect(foo.stuff.url).to.exist;
                expect(foo).to.have.deep.property('stuff.url').to.contain('http://');
              });

              done();

        })
        .catch(function(err){
            done(err);
        })

结果我只需要处理.catch并调用done(err)来查看控制台中的失败测试。

相关问题