如何在之前的描述中跳过下一个描述()错误?茉莉花试验 [英] how to skip to next describe() upon error in previous describe? jasmine test

查看:68
本文介绍了如何在之前的描述中跳过下一个描述()错误?茉莉花试验的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此类代码,以便在其中一个 it() describe c>函数:

i'm using such code in order to stop the entire describe upon an error in one of the it() functions:

if(this.results_.failedCount > 0) {
        //next step will finish the test
   jasmine.Queue.prototype.next_ = function () {
   // to instead skip to the end
        this.onComplete();
   }
}

我得到了:如何在测试失败后让jasmine.js停止?

但是,如果我在文件中有很少的描述块,并且第一个描述失败,我希望它继续下一个描述而不是杀死整个测试。
我该怎么办?

however, if i have few describe blocks in the file, and the first describe fails, i would like it to continue to the next describe and not kill the entire test. how can i do it?

谢谢

推荐答案

Asher,
我在afterEach中使用了解决方法中的代码,它似乎有效。谢谢:)
如果你想要其他规格失败(而不是只是跳过)
在if:

Asher, I've used your code from the workaround inside afterEach and it seems to work. Thanks :) In case you want the other specs to fail (and not just skipped) add the following code inside the if:

中添加以下代码(currentIt&&(currentIt.results_.failedCount!== 0)){

if (currentIt && (currentIt.results_.failedCount !== 0)) {

var currentSuite = jasmine.getEnv().currentSpec.suite.id;
var currentSpec = jasmine.getEnv().currentSpec.id;

//get number of children (its)
var numChildren = jasmine.getEnv().currentSpec.suite.children().length;

//skip after last child
jasmine.getEnv().currentRunner().suites()[currentSuite].queue.index = numChildren-1;
//finish the current spec now (otherwise the spec will be reported after his siblings)
jasmine.getEnv().currentSpec.finish();
jasmine.getEnv().currentSpec.finishCallback = function(){};

//report the other sibilings as failures
for (var index = currentSpec+1; index < numChildren ; index++){
   var spec = jasmine.getEnv().currentSpec.suite.children()[index];
   jasmine.getEnv().currentSpec = spec;
   (new AddIndexPlugin()).doBefore();

   spec.results().failedCount = 1;
   spec.results().totalCount = 1;
   spec.results().skipped = true;
   spec.results().getItems().push(new jasmine.ExpectationResult({actual:'skipping test because previous test failed',passed:false , message:'skipping test because previous test failed',trace:'skipping test because previous test failed'}));

   spec.finish();}

现在Jasmine真的是E2E测试框架,而不仅仅是单元测试框架。

Now Jasmine is really a E2E testing framework and not just unit test framework.

这篇关于如何在之前的描述中跳过下一个描述()错误?茉莉花试验的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆