我正在运行我的测试并注意到:
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!`)
}
谢谢!
答案 0 :(得分:2)
许多测试框架中的待测试是测试跑步者决定不运行。有时这是因为测试被标记为跳过。有时因为测试只是TODO的占位符。
对于Mocha,documentation表示待处理的测试是没有任何回调的测试。
你确定你正在看好考试吗?
答案 1 :(得分:1)
测试had a callback(即实际功能,未完成)但重构代码解决了问题。问题是如何运行期望错误的代码:
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!`)
}
});
答案 2 :(得分:0)
当您无意中提前关闭测试的it
方法时,Mocha最终会将测试显示为“待处理”,例如:
// 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...
});
答案 3 :(得分:0)
当我遇到此问题时,未决的错误是当我使用skip定义描述测试时,忘记了删除它,就像这样:
describe.skip('padding test', function () {
it('good test', function () {
expect(true).to.equal(true);
})
});
并运行它,我得到了输出
Pending test 'good test'
,当我删除了描述测试中的 skip 标志时,它又可以正常工作了。