gpt4 book ai didi

javascript - 如何在上一个描述出错时跳到下一个描述()? Jasmine 测试

转载 作者:行者123 更新时间:2023-11-30 06:26:20 28 4
gpt4 key购买 nike

我使用这样的代码是为了在 it() 函数之一出现错误时停止整个 describe:

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

我从:How can I make jasmine.js stop after a test failure?

但是,如果文件中的描述 block 很少,并且第一个描述失败,我希望它继续下一个描述而不是终止整个测试。我该怎么做?

谢谢

最佳答案

亚设,我已经在 afterEach 中使用了您的解决方法中的代码,它似乎有效。谢谢 :)如果您希望其他规范失败(而不仅仅是跳过)在 if 中添加以下代码:

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 确实是一个端到端的测试框架,而不仅仅是单元测试框架。

关于javascript - 如何在上一个描述出错时跳到下一个描述()? Jasmine 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20858717/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com