如果一个失败,从规范中跳过后续的Mocha测试

lla*_*err 46 javascript mocha.js node.js

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

我正在使用mocha-as-promised,因此代码可能看起来与usuall不同

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!");
          });
      });
    });

  });
});
Run Code Online (Sandbox Code Playgroud)

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

编辑:似乎我只是让我的测试错误,将等待一段时间才能删除问题

编辑:

正如我在评论中回复 - 我已经在摩卡谷歌团体中收到了这个答案,但还有一些其他限制我没有提到 - 我正在使用grunt-simple-mocha和我检查代码 - 当我没有保释选项将选项传递给mocha构造函数

我没能找到命令行中的选项传递给Suite实例的位置,以及它可能是唯一的一行,因为我看到它是一个

suite.bail(this.bail());
Run Code Online (Sandbox Code Playgroud)

这对我来说很奇怪

我想我会在mocha github页面上打开问题,也许他们会延迟通过保释设置的选项,或者只是解释一下我做错了什么以及如何以其他方式解决我的问题

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

Bea*_*eau 102

摩卡在第一次测试失败后支持纾困,那是你想要的吗?

来自mocha --help:

-b, --bail                      bail after first test failure
Run Code Online (Sandbox Code Playgroud)