小编典典

如果一项失败,请从规范中跳过后续的摩卡测试

node.js

it如果其中一个失败,我无法找到一种方法来停止其中的某些部分

我正在使用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!");
          });
      });
    });

  });
});

我想如果should navigate to test page and check title失败的话 submit element should be clicked1应该跳过

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

编辑:

正如我在评论中回答的那样-我已经在摩卡Google网上论坛中收到了此答案,但是还有其他一些我没有提到的限制-我正在使用grunt-simple-
mocha并且我检查了代码-当我查看保释金时,将选项传递给摩卡构造函数

我无法找到命令行中的选项传递到Suite实例的位置,而我看到的唯一行可能是

suite.bail(this.bail());

这对我来说很奇怪

我认为我将在mocha github页面上打开问题,也许他们以后会用保释金设置扩展通过的选项,或者只是向我解释我做错了什么以及如何以其他方式解决我的问题

编辑:现在,根据
https://github.com/visionmedia/mocha/commit/f0b441ceef4998e570a794dcff951bf2330eb0c5
最新的Mocha,有保释箱可供选择。感谢作者!


阅读 361

收藏
2020-07-07

共1个答案

小编典典

摩卡咖啡支持在第一次测试失败后进行收费,这就是您想要的吗?

来自mocha --help

-b, --bail                      bail after first test failure
2020-07-07