سؤال

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 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 combined 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 command works for me

$ node_modules/.bin/mocha test/file1.js test/file2.js
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top