考虑在描述块内有一个描述块和两个块。
describe(""){
it(""){
} //if this block fails script should not execute next block
it(""){
}
}
如果第一次阻止失败,脚本不应该执行下一次阻止。你如何在量角器中实现这一目标。请帮忙。
答案 0 :(得分:1)
示例:的
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中,一个用于两个或一个,并手动处理捕获的错误,然后使用Jasmine失败()失败。
答案 1 :(得分:1)
您可以将块封装在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
}
}