[英]Mocha and NightmareJS- continue test
我遇到一個簡單的問題,我有大約5個測試屬於一個組,其中一個是我強迫它們失敗,但我無法退出失敗狀態:
.goto(url)
.wait('#element')
.evaluate(fnc...)
wait('#newelement')
....
evaluate(function(){
return document.querySlector('#myid').innerText
})
.then(function(result) {
result.should.equal('1');// I know I am expecting 2
done();
})
// will never be executed.
.then.....
//拋出以下消息。 錯誤:超時超過15000ms。 確保此測試中調用了done()回調。
沒關系,但是在此失敗之后,我還需要進行其他測試,但是我似乎無法繼續進行測試,也無法采用一種優雅的方式來報告失敗而又不影響其余測試。
如果要強制測試失敗,則可以調用done
作為參數傳遞錯誤:
done(new Error('this is my error message'))
因此,在您的情況下,如下所示:
.goto(url)
.wait('#element')
.evaluate(fnc...)
wait('#newelement')
....
evaluate(function(){
return document.querySlector('#myid').innerText
})
.then(function(result) {
done(new Error('Please test, fail because I want you to.'));
})
// will never be executed.
.then.....
另外,請注意,由於多次調用要在同一鏈調用上進行evaluate
,因此原始代碼可能不起作用,請參閱此答案以獲取更多詳細信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.