Jest: --testNamePattern doesn't work as expected -- runs all tests under the file

Created on 4 Mar 2019  Β·  2Comments  Β·  Source: facebook/jest

Expected Behavior

command

npm test -t="needsCheckInOrOut"

should filter out describe blocks having title doesn't start with needsCheckInOrOut, ie. runs single describe block like below.

2019-03-04 7 58 31

Current Behavior

Runs all describe blocks under the file.

2019-03-04 7 56 51

Context

I have a single test file named index.test.ts and it has some describe blocks that takes longer time to execute. So I want to run certain describe blocks by specifying their title via -t option.
Is that possible through -t option? Or if it's not, is there any alternative for specifying certain describe block under the test file via CLI?

For example, I have those test cases.

    βœ“ input: Jan 13–18, 2019 (4ms)
    βœ“ input: Jan 13–15, 2019 (11ms)
    βœ“ input: Jan 15–17, 2019 (1ms)
    βœ“ input: Jan 15–Feb 1, 2019
    βœ“ input: Dec 31–Jan 15, 2019
  detect language
    βœ“ should detect `μ•ˆλ…•ν•˜μ„Έμš”!μˆ™μ†Œ λ¬Έμ˜λ“œλ¦¬κ³ μ‹Άμ–΄μ„œμš”οΏ½ν˜Ήμ‹œ μ§‘μ—μ„œ λ°”λ‹€κ°€ λ³΄μ΄λ‚˜μš”?` to `ko` (730ms)
    βœ“ should detect `hello, we are coming from germany and looking forward to staying at your place :)` to `en` (391ms)
    βœ“ should detect `Qu'est-ce que vous faites?` to `en` (368ms)
    βœ“ should detect `.` to `ko` (353ms)
    βœ“ should detect `` to `ko` (593ms)
  send gmail message
    βœ“ can send mail subject and body containing non ascii characters (1775ms)
  send message
    βœ“ case check-in (17277ms)
    βœ“ case check-out (13311ms)
    βœ“ case reservation-confirmed (15373ms)

And if I want to test only detect language describe block, then I can to use

npm test -t="detect language"

As a result, only one describe block that has matching title would be tested.

  detect language
    βœ“ should detect `μ•ˆλ…•ν•˜μ„Έμš”!μˆ™μ†Œ λ¬Έμ˜λ“œλ¦¬κ³ μ‹Άμ–΄μ„œμš”οΏ½ν˜Ήμ‹œ μ§‘μ—μ„œ λ°”λ‹€κ°€ λ³΄μ΄λ‚˜μš”?` to `ko` (730ms)
    βœ“ should detect `hello, we are coming from germany and looking forward to staying at your place :)` to `en` (391ms)
    βœ“ should detect `Qu'est-ce que vous faites?` to `en` (368ms)
    βœ“ should detect `.` to `ko` (353ms)
    βœ“ should detect `` to `ko` (593ms)

npx envinfo --preset jest

  System:
    OS: macOS 10.14.3
    CPU: (4) x64 Intel(R) Core(TM) i5-6360U CPU @ 2.00GHz
  Binaries:
    Node: 10.15.1 - ~/.nvm/versions/node/v10.15.1/bin/node
    npm: 6.8.0 - ~/.nvm/versions/node/v10.15.1/bin/npm
  npmPackages:
    jest: ^23.6.0 => 23.6.0 

Most helpful comment

Try running the command like this:
npm test -- -t="needsCheckInOrOut"

As it is stated on the documentation:

Using with npm scripts
If you run Jest via npm test, you can still use the command line arguments by inserting a -- between npm test and the Jest arguments.

All 2 comments

Try running the command like this:
npm test -- -t="needsCheckInOrOut"

As it is stated on the documentation:

Using with npm scripts
If you run Jest via npm test, you can still use the command line arguments by inserting a -- between npm test and the Jest arguments.

Closing this issue as Luanf's answer works.

Was this page helpful?
0 / 5 - 0 ratings