2
考慮有一個描述塊和兩個塊在描述塊內。如何不執行它當上面的塊阻塞失敗
describe(""){
it(""){
} //if this block fails script should not execute next block
it(""){
}
}
如果第一個塊阻塞失敗,腳本不應該執行下一個阻塞塊。你如何在量角器中實現這一點。請幫忙。
考慮有一個描述塊和兩個塊在描述塊內。如何不執行它當上面的塊阻塞失敗
describe(""){
it(""){
} //if this block fails script should not execute next block
it(""){
}
}
如果第一個塊阻塞失敗,腳本不應該執行下一個阻塞塊。你如何在量角器中實現這一點。請幫忙。
例子:
describe('first test', function() {
it('Second test', function (done) { /* some code */});
it('Third test', function (done) { /* some code */});
it('employee test', function (done) {
//It should be an object
var employee = getEmployee();
expect(employee).not.toBeNull();
expect(employee.name).not.toBeNull(); // if employee == null will not stop here and throw an exception later
expect(employee.name).toBe(‘tarun’);
done();
});
it('employee test', function (done) { });
});
我建議你換行第二和第三預期的try/catch,一個雙方還是各一個,並手動處理捕獲錯誤的,那麼失敗,茉莉花失敗()。
您可以將塊封裝在try-catch
之內。然後,您可以使用一些布爾值來檢查第一個塊是否成功執行並執行第二個塊。
describe(""){
try{
var firstSuccess = false;
it(""){
//do whatever...
firstSuccess = true; //set firstSuccess to true at end of it block
} //if this block fails script should not execute next block
if(firstSuccess){ //execute second it block only after first it executes successfully
it(""){
}
}
}catch(err){
//handle error here
}
}
難道你不能將代碼包裝在'try ... catch'塊中嗎? – Nisarg