[英]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.