Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run single test of a specific test suite in Jest

I have a file called "test-file-1", within it i have a few describes (test suites) with unique names and inside them i have tests which may have similar names across test suites.

To run a single test suite or test i type the command below.

npm test -- -t "Test Suite or Test"

I'm trying to figure out how to run a single test of a specific test suite.

like image 990
Gabriel Souza Avatar asked Jul 15 '19 18:07

Gabriel Souza


People also ask

How do I run a specific test suite in Jest?

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: Hit p while in watch mode to enter a regex for the filename you'd like to run.

How do you run a single test in a Jest test?

In order to run a specific test, you'll need to use the jest command. npm test will not work. To access jest directly on the command line, install it via npm i -g jest-cli or yarn global add jest-cli . Then simply run your specific test with jest bar.

Does Jest run tests concurrently?

By the way @trusktr Jest DOES run tests in parallel, just not ones in the same file. So you can run into issues with interference between tests if they are running on the same database.

How do I run a jest test from a single file?

So if you only want to run one test within a file that has many test cases within a suite of testcases that consists of many files you have to unfortunately run that single file jest myTestFile.test.js node <path-to-jest> -i <you-test-file> -c <jest-config> -t "<test-block-name>"

How do I run only one unit test at a time?

Jest provides a convenient way to run only one unit test at a time. First, run only the single test file which contains the single test to run, similar to the following: The single test in the suite that we wish to run should be changed to use it.only () as in the example below:

How to exclude a test in jest?

You can also use f or x to focus or exclude a test. For example fit ('only this test will run', () => { expect (true).toBe (false); }); it ('this test will not run', () => { expect (true).toBe (false); }); xit ('this test will be ignored', () => { expect (true).toBe (false); }); xit did work for me, but fit does not. i am using [email protected].

Is it possible to run a single test from a file?

Yes, but i didn't found a way to run a single test of a specific test suite. will run only the test (or group) named "test name" of this specific file. that's the problem, i have a file with multiple tests with the same or similar name, the only thing that differs them is the test suite.


2 Answers

Give the path of the file you want to test :

npm test path/of/your/testfile.js -t "test name"

will run only the test (or group) named "test name" of this specific file.

like image 51
colinux Avatar answered Nov 04 '22 16:11

colinux


After trying a lot of different things i found out that it was simpler than i thought.

You simply have to put the test after the test suite in the same string:

npm test -- -t "<Test Suite> <Test>"
like image 38
Gabriel Souza Avatar answered Nov 04 '22 16:11

Gabriel Souza