[英]Is there a way to skip all tests in a suite if a certain conditions fail - JavaScript Jasmine?
如果某些條件失敗,有沒有辦法跳過套件中的所有測試? 即)如果網頁未打開,則運行 rest 測試沒有意義,因為它們都取決於在運行任何測試之前打開的網頁。
我們可以使用 pending() 來跳過當前測試,但是如果所有其他測試都依賴於 checkCondition 為真,是否有一種方法可以立即跳過套件中的所有測試或下面的測試?
我嘗試在 beforeAll 塊中添加 pending() ,以嘗試跳過所有測試,因為 beforeAll 在任何事情之前運行。
請幫忙。 我正在使用 WebdriverIO 和 Jasmine。 謝謝!
let checkCondition = false;
describe(`My Test Suite`, () => {
beforeAll(async () => {
// EDIT - returnBoolean() is another method that logs into the
// page and returns true or false
let setCheckCondition = returnBoolean();
if (setCheckCondition) {
checkCondition = true;
console.log(`in true block`);
} else {
console.log('Skip tests below'); // HELP <-- since checkCondition is false, all tests below should fail
pending();
}
});
it(`Test 1`, () => {
if (checkCondition != undefined) {
console.log("checkCOndition is defined")
} else {
pending();
}
});
it(`Test 2`, () => {
if (checkCondition) {
// check
} else {
console.log('Skip this test');
pending();
}
});
it(`Test 3`, () => {
console.log("skip this test too")
});
});
如果您必須在beforeAll
中設置checkCondition
然后最終從那里中止,那么 github 上似乎存在一個持續的問題( https://github.com/jasmine/jasmine/issues/1533 )
否則,如果在測試套件開始之前可以知道checkConditon
(我不明白為什么不這樣做),您只需將beforeAll
替換為類似
if (!checkCondition) return
或者直接跳過整個調用來首先describe
編輯:您可以像這樣跳過整個測試套件:
let checkCondition = returnBoolean();
if (checkCondition) {
describe(`My Test Suite`, () => {
it(`Test 1`, () => {
// run test 1 normally
});
it(`Test 2`, () => {
// run test 2 normally
});
it(`Test 3`, () => {
// run test 3 normally
});
});
} else {
console.log("checkCondition is false. Skipping all tests!");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.