最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Running test cases selectively with Mocha - Stack Overflow

programmeradmin4浏览0评论

There is a total of 20 test case files. I want to test a particular set of 10 test cases. Is there any script file or any other method to run the test cases selectively with Mocha?

There is a total of 20 test case files. I want to test a particular set of 10 test cases. Is there any script file or any other method to run the test cases selectively with Mocha?

Share Improve this question edited Nov 19, 2015 at 11:44 Louis 152k28 gold badges286 silver badges329 bronze badges asked Apr 8, 2014 at 12:16 user1517716user1517716 1073 silver badges11 bronze badges 1
  • yes i am asking about JavaScript Mocha – user1517716 Commented Apr 9, 2014 at 4:46
Add a ment  | 

3 Answers 3

Reset to default 5

There are two principal ways to specify a subset of tests to run:

  1. You can give Mocha the name of the file that contains the tests you want to run:

    $ mocha path/to/file
    

    It is possible to give paths to multiple files if needed. For instance, if you have 10 test files and want to run all the tests from only 2 of them, you could give the paths of the 2 files.

    This method relies on you splitting your tests into separate files according to a logic that suits your situation.

  2. You can use the --grep option:

    $ mocha --grep pattern
    

    The pattern is a regular expression that Mocha will use to test each test title. Each test for which the pattern matches will be run.

The two methods could be bined to run only tests that match a pattern and that are from one specific file: $ mocha --grep pattern path/to/file

mocha.describe("test1", () => {
    mocha.it("test1_1", (done) => {
        done();
    })
    mocha.it.only("test1_2", (done) => {
      done();
    })
})
OutPut : 
 test2
✔ test2_2 //because of it.only

Following mand works for me

$ node_modules/.bin/mocha test/file1.js test/file2.js
发布评论

评论列表(0)

  1. 暂无评论