How do I run a single test using Jest?

后端 未结 14 1873
轮回少年
轮回少年 2020-12-12 10:22

I have a test \'works with nested children\' within the file fix-order-test.js.

Running the below runs all the tests in the file.

jest fix-order-test         


        
14条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-12 10:35

    As mentioned in other answers, test.only merely filters out other tests in the same file. So tests in other files would still run.

    So to run a single test, there are two approaches:

    • Option 1: If your test name is unique, you can enter t while in watch mode and enter the name of the test you'd like to run.

    • Option 2:

      1. Hit p while in watch mode to enter a regex for the filename you'd like to run. (Relevant commands like this are displayed when you run Jest in watch mode).
      2. Change it to it.only on the test you'd like to run.

    With either of the approaches above, Jest will only run the single test in the file you've specified.

提交回复
热议问题