【问题标题】:How to grep a test in Mocha with a specific name and under a specific parent?如何在 Mocha 中使用特定名称和特定父级 grep 测试?
【发布时间】:2021-12-07 11:16:25
【问题描述】:

考虑以下测试用例:

describe("parent1", () => {
    it("mytest", () => {
        // ...
    });
});

describe("parent2", () => {
    it("mytest", () => {
        // ...
    });
});

describe("parent1", () => {
    it("myothertest", () => {
        // ...
    });
});

describe("parent2", () => {
    it("myothertest", () => {
        // ...
    });
});

我基本上希望能够通过命令行在parent1 下运行mytest。

尝试

如果我尝试以下操作:

mocha --grep 'mytest'

它将最终运行:

  • parent1/mytest
  • parent2/mytest

如果我尝试:

mocha --grep 'parent1'

它将最终运行:

  • parent1/mytest
  • parent1/myothertest

如何做到这一点?

【问题讨论】:

  • mocha --grep 'parent1/mytest' 呢?
  • @evolutionxbox 会起作用吗?我可以试试
  • 似乎不起作用,它找不到任何要运行的测试

标签: javascript mocha.js


【解决方案1】:

实际上很简单,因为它被评估为正则表达式:

mocha --grep 'parent1 mytest'

使用空格似乎是解决方案。我可以成功地确定这样的测试。

注意事项

如果测试名称中有空格,它也可以:

describe("parent1", () => {
    it("my test", () => {
        console.log("AAA");
    });
});

describe("parent2", () => {
    it("my test", () => {
        console.log("BBB");
    });
});

describe("parent1", () => {
    it("my other test", () => {
        console.log("CCC");
    });
});

describe("parent2", () => {
    it("my other test", () => {
        console.log("DDD");
    });
});

跑步:

mocha --grep 'parent1 my test'

会按预期工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-15
    • 1970-01-01
    • 1970-01-01
    • 2012-04-29
    • 2015-05-11
    • 1970-01-01
    • 2019-04-18
    • 1970-01-01
    相关资源
    最近更新 更多