javascript 如果失败,则跳过规范中的后续 Mocha 测试

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13954531/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 20:17:52  来源:igfitidea点击:

Skip subsequent Mocha tests from spec if one fails

javascriptnode.jsmocha

提问by llamerr

I can't find a way how to stop some part of it's from run if one of them failed

it如果其中一个失败,我找不到如何阻止's 的某些部分运行的方法

I'm using mocha-as-promised, so the code might look different from as usuall

我正在使用mocha-as-promised,所以代码看起来可能与往常不同

describe("remote promises", function() {
  describe("browsing", function() {
    describe("getting page", function() {
      it("should navigate to test page and check title", function() {
        this.timeout(TIMEOUT);
        return browser.get("http://admc.io/wd/test-pages/guinea-pig.html").then(function() {
          return browser.title();
        }).then(function(title) {
          return assert.ok(~title.indexOf("I am a page title - Sauce Labs"), "Wrong title!");
        });
      })
      it("submit element should be clicked1", function() {
        this.timeout(TIMEOUT);
        return browser.elementById("submit").then(function(el) {
          return browser.clickElement(el);
        }).then(function() {
            return browser["eval"]("window.location.href");
          }).then(function(location) {
            assert.ok(~location.indexOf("http://"), "Wrong location!");
          });
      })
    });
    describe("clicking submit", function() {
      it("submit element should be clicked2", function() {
        this.timeout(TIMEOUT);
        return browser.elementById("submit").then(function(el) {
          return browser.clickElement(el);
        }).then(function() {
            return browser["eval"]("window.location.href");
          }).then(function(location) {
            assert.ok(~location.indexOf("http://"), "Wrong location!");
          });
      });
    });

  });
});

and i want that if should navigate to test page and check titleis failed then submit element should be clicked1should be skipped

我希望如果should navigate to test page and check title失败,那么 submit element should be clicked1应该跳过

EDIT: seems i'm just making my tests wrong, will wait for some time before deleting question

编辑:似乎我只是让我的测试错了,在删除问题之前会等待一段时间

EDIT:

编辑:

as i replied in comment - i already received this answer in mocha google groups, but there are some other restrictions i not mentioned in question - i'm using grunt-simple-mocha and as i inspected code - there is no bail option when i pass options to mocha constructor

正如我在评论中回答的那样 - 我已经在 mocha 谷歌群组中收到了这个答案,但是还有一些我没有提到的其他限制 - 我正在使用 grunt-simple-mocha 并且在我检查代码时 - 当我没有保释选项时将选项传递给 mocha 构造函数

i failed to find where are options from command line are passed to Suite instance, and the only line where it may be as i see it is a

我找不到命令行中的选项传递给 Suite 实例的位置,而我看到的唯一一行是

suite.bail(this.bail());

which looks weird for me

这对我来说看起来很奇怪

i think i will open issue at mocha github pages, maybe they will extend passed options with bail setting later, or just explain me what i did wrong and how i can solve my problem in other way

我想我会在 mocha github 页面上打开问题,也许他们稍后会使用保释设置扩展传递的选项,或者只是解释我做错了什么以及我如何以其他方式解决我的问题

EDIT: and now, according to https://github.com/visionmedia/mocha/commit/f0b441ceef4998e570a794dcff951bf2330eb0c5latest Mocha have bail option from the box. Thanks to authors!

编辑:现在,根据https://github.com/visionmedia/mocha/commit/f0b441ceef4998e570a794dcff951bf2330eb0c5最新的摩卡从框中有保释选项。感谢作者!

回答by Beau

Mocha supports bailing after the first test failure, is that what you want?

摩卡支持第一次测试失败后退出,这就是你想要的吗?

From mocha --help:

来自mocha --help

-b, --bail                      bail after first test failure