[英]What does 'pending' test mean in Mocha, and how can I make it pass/fail?
我正在运行我的测试并注意到:
18 passing (150ms)
1 pending
我以前没见过这个。 以前测试要么通过要么失败了。 超时导致失败。 我可以看到哪个测试失败了,因为它也是蓝色的。 但它有一个超时。 这是一个简化版本:
test(`Errors when bad thing happens`), function(){
try {
var actual = doThing(option)
} catch (err) {
assert(err.message.includes('invalid'))
}
throw new Error(`Expected an error and didn't get one!`)
}
谢谢!
测试可以最终被所示摩卡为“待定”当你不经意间关闭了测试的it
方法早,如:
// Incorrect -- arguments of the it method are closed early
it('tests some functionality'), () => {
// Test code goes here...
};
it
方法的参数应包括测试函数定义,如:
// Correct
it('tests some functionality', () => {
// Test code goes here...
});
测试有一个回调 (即一个实际的功能,没有完成),但重构代码解决了这个问题。 问题是如何运行期望错误的代码:
test('Errors when bad thing happens', function() {
var gotExpectedError = false;
try {
var actual = doThing(option)
} catch (err) {
if ( err.message.includes('Invalid') ) {
gotExpectedError = true
}
}
if ( ! gotExpectedError ) {
throw new Error(`Expected an error and didn't get one!`)
}
});
当我遇到这个问题时,挂起的错误就是当我用skip定义一个describe测试时,忘了删除它,就像那样:
describe.skip('padding test', function () {
it('good test', function () {
expect(true).to.equal(true);
})
});
并且确实运行了它,我得到了输出
Pending test 'good test'
当我在描述测试中删除跳过标志时,它再次起作用..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.