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
3 Answers
Reset to default 5There are two principal ways to specify a subset of tests to run:
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.
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