tdd - mocha 测试用例的条件执行

标签 tdd mocha.js

我正在使用 Mocha 与 Sinon JS 和 Phantom Js 来测试来自特定页面的谷歌分析调用。到目前为止,我可以通过为每个元素编写不同的测试用例来为单个元素执行静态测试用例。喜欢 :

describe("Site Home Page Test", function() {

    it ("Global Search track", function() {
        var link = $('button.search');
        link.click();
    });

});

现在的问题是,如果只找到 $('elem') 是否可以执行测试用例?像这样:
describe("Site Home Page Test", function() {

  //  if(condition) {

        it ("Global Search track", function() {
            var link = $('button.search');
            link.click();
        });

  //  }

});

最佳答案

我不确定我是否完全错过了这个问题,但是您可以完全按照自己的方式编写条件测试用例:

describe("Some module", function() {
    if(false) {
        it ("should NOT run this test case", function() { });
    }

    it("should run this test case", function() { });
});

只会运行 这不在 if 语句中。

Some module
  ✓ should run this test case 

1 passing (5 ms)

关于tdd - mocha 测试用例的条件执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17672825/

相关文章:

testing - 当 mocha + enzyme + chai 包装在 Provider 组件中时,如何测试 react-native 组件

javascript - 如何从 beforeEach() 传递值来测试? Mocha/Chai

web-services - CI CD 工作流程中集成测试的范围

asp.net - 如何模拟/伪造 ASP.Net Web 表单中的 session 对象?

android - Android App SDLC 中的测试组件?

node.js - 是否有 .mocha 文件可以在其中指定默认值,例如 --no-colors?

node.js - 配置 Mocha 以持续运行测试失败

node.js - 当抛出的任何错误都没有冒泡时,如何在 promise 中做出断言?

c# - 单元测试 C# 属性

javascript - beforeEach 具有用于 Mocha 测试的套件语法