如果一个失败,从规范中跳过后续的Mocha测试 [英] Skip subsequent Mocha tests from spec if one fails

查看:92
本文介绍了如果一个失败,从规范中跳过后续的Mocha测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

I'm using mocha-as-promised, so the code might look different from as 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!");
          });
      });
    });

  });
});

我希望如果导航到测试页面并检查标题失败然后
应该点击提交元素1 应该被跳过

and i want that if should navigate to test page and check title is failed then submit element should be clicked1 should be skipped

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

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

编辑:

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

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

我无法找到命令行中的选项传递给Suite实例的位置,并且是唯一的它可能是我认为它是

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.bail(this.bail());

这对我来说很奇怪

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

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

编辑:现在,根据 https://github.com/visionmedia/mocha/commit/ f0b441ceef4998e570a794dcff951bf2330eb0c5
最新的Mocha从包装盒中获得保释选项。感谢作者!

推荐答案

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

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

来自 mocha --help

-b, --bail                      bail after first test failure

这篇关于如果一个失败,从规范中跳过后续的Mocha测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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