相关疑难解决方法(0)

有没有办法让Chai使用异步Mocha测试?

我正在使用浏览器运行器在Mocha中运行一些异步测试,我正在尝试使用Chai的期望样式断言:

window.expect = chai.expect;
describe('my test', function() {
  it('should do something', function (done) {
    setTimeout(function () {
      expect(true).to.equal(false);
    }, 100);
  }
}
Run Code Online (Sandbox Code Playgroud)

这不会给我正常的失败断言消息,而是我得到:

Error: the string "Uncaught AssertionError: expected true to equal false" was thrown, throw an Error :)
    at Runner.fail (http://localhost:8000/tests/integration/mocha/vendor/mocha.js:3475:11)
    at Runner.uncaught (http://localhost:8000/tests/integration/mocha/vendor/mocha.js:3748:8)
    at uncaught (http://localhost:8000/tests/integration/mocha/vendor/mocha.js:3778:10)
Run Code Online (Sandbox Code Playgroud)

所以它显然正在捕捉错误,它只是没有正确显示它.任何想法如何做到这一点?我想我可以用一个错误对象调用"完成",但后来我失去了像柴这样的东西的所有优雅,它变得非常笨重......

javascript unit-testing mocha.js

79
推荐指数
3
解决办法
4万
查看次数

如何使用mocha使用'done();'进行异步测试?

我正在尝试使用该调用编写asynchronous测试。到目前为止,这是我的代码。mochadone();

it('should have data.', function () {
    db.put(collection, key, json_payload)
        .then(function (result) {
            result.should.exist;
            done();
        })
        .fail(function (err) {
            err.should.not.exist;
            done();
        })
})
Run Code Online (Sandbox Code Playgroud)

但是,结果是代码仅在不等待 then的情况下执行,否则将无法真正返回结果。是否done();需要在代码中的其他位置?

还在此处发布了整个仓库:https : //github.com/Adron/node_testing_testing

javascript testing asynchronous mocha.js node.js

3
推荐指数
1
解决办法
2054
查看次数