在我们的mocha测试中,有时我们有bug和抛出异常,当这些异常被抛出时,后续的断言不会被调用,我们的测试可能会通过,即使有一些错误。
// this would pass
it('adsf', async () => {
assert.equal(1,1)
var foo = undefined;
foo.hi(); // throw exception
assert.equal(1,2) // assert not called
});
我们尝试将其包装在try catch中,如下所示
// this would fail, but not say why
it('adsf', async () => {
try {
assert.equal(1,1)
// var foo = undefined;
// foo.hi();
assert.equal(1,2)
} catch (err) {
assert.fail(err) // if fail, such as the 1,2 case above, the line number of the error is not shown
}
});
但是catch
案例隐藏了一些失败的断言信息。如果任何人有任何建议,将不胜感激。
https://stackoverflow.com/questions/56762035
复制相似问题