Jasmine/量角器:在 beforeEach 中停止失败测试 [英] Jasmine/Protractor: stop test on failure in beforeEach
问题描述
我目前正在编写测试量角器,我想知道是否有可能在 beforeEach 中的某些内容失败时立即取消测试执行(并返回一些有用的消息,例如前提条件失败:无法登录用户").IE.我在 beforeEach 中有一些帮助方法,用于登录用户然后进行一些设置.
I am currently writing tests protractor and I was wondering if there is some possibility to cancel test execution as soon as something in the beforeEach fails (and return some useful message like "precondition failed: could not login user"). I.e. I have some helper methods in the beforeEach that login the user and then do some setup.
beforeEach:
1) login user
2) set some user properties
如果第一个步骤失败,显然执行第二个步骤没有任何意义(实际上它非常有害,因为用户被锁定,这不好).我尝试在第一步中添加一个期望",但第二步仍然执行 -> 新的想法.
Obviously it does not make any sense to execute the 2nd step if the first one fails (actually its quite harmful as the user gets locked which is not nice). I tried to add an "expect" as part of the 1st step, but the 2nd step was still executed -> fresh out of ideas.
推荐答案
jasmine.Env.prototype.bailFast = function() {
var env = this;
env.afterEach(function() {
if (!this.results().passed()) {
env.specFilter = function(spec) {
return false;
};
}
});
};
然后只需调用:
jasmine.getEnv().bailFast();
(感谢 hurrymaplelad,他编写了一个可以做到这一点的 npm,但是你不需要使用它)
(credit goes to hurrymaplelad who wrote an npm that does just that, however you don't need to use it)
这篇关于Jasmine/量角器:在 beforeEach 中停止失败测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!