4

Im testing my app. When I run 'npm test' I want to see in the terminal all tests. I have one file called auth.test.js with all my tests.

So my output when i run npm test is this one:

> jest --forceExit

 PASS  src/test/auth.test.js
  /LOGIN testing
    ✓ Should not login a unexistent username. (22ms)
    ✓ Should not login with incorrect credentials. (63ms)
    ✓ Should not login with empty fields. (2ms)
    ✓ Should login a moked user. (67ms)
  /SIGNUP testing
    ✓ Should not sign up a new user with invalid password. (3ms)
    ✓ Should not sign up a new user with invalid username. (2ms)
    ✓ Should sign up a new user. (72ms)
    ✓ Should not sign up a existing user. (4ms)
    ✓ Should not sign up with empty fields. (3ms)

Test Suites: 1 passed, 1 total
Tests:       9 passed, 9 total
Snapshots:   0 total
Time:        1.114s, estimated 2s
Ran all test suites.

Thats fine. I can see all tests with details.

Now, I want to add a new file with tests, called api.tests.js.

Then, when I run 'npm test' i see this output:

> jest --forceExit

 PASS  src/test/api.test.js
 PASS  src/test/auth.test.js

Test Suites: 2 passed, 2 total
Tests:       10 passed, 10 total
Snapshots:   0 total
Time:        1.589s, estimated 2s
Ran all test suites.

After read the jest documentation (cli article) I cant found how to see the details, like I see when testing 1 file, but when testing more than 1 file.

Is it posible? How to do it?

Lin Du
  • 88,126
  • 95
  • 281
  • 483
franlol
  • 51
  • 7

2 Answers2

2

You're probably getting npm --verbose results which look different. To get jest --verbose, add two hyphens to your command: -- --verbose. I had the same problem and it worked for me.

I got the solution from here: Is there an option to show all test descriptions when I run jest tests?

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Kiira
  • 46
  • 7
  • I think this is the correct answer. Tried the other config thing. It didn’t do anything. Sure seems like output is condensed after suite one. – Martin May 18 '23 at 20:55
1

You need modify the configuration of testMatch in your jest.config.js file.

The glob patterns Jest uses to detect test files. By default it looks for .js, .jsx, .ts and .tsx files inside of tests folders, as well as any files with a suffix of .test or .spec (e.g. Component.test.js or Component.spec.js). It will also find files called test.js or spec.js.

Your new test file named api.tests.js, so you need add a glob pattern

'**/?(*.)+(specs|tests).[jt]s?(x)' into the testMatch configuration.

For example, jest.config.js:

module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'enzyme',
  setupFilesAfterEnv: ['jest-enzyme'],
  testEnvironmentOptions: {
    enzymeAdapter: 'react16'
  },
  coverageReporters: ['json', 'text', 'lcov', 'clover'],
  testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)', '**/?(*.)+(specs|tests).[jt]s?(x)']
};

Unit test result:

☁  jest-codelab [master] ⚡  npm t

> jest-codelab@1.0.0 test /Users/ldu020/workspace/github.com/mrdulin/jest-codelab
> jest --detectOpenHandles

 PASS  src/stackoverflow/58663681/api.tests.js
  ✓ t1 (4ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        3.883s
Ran all test suites.
Lin Du
  • 88,126
  • 95
  • 281
  • 483
  • 1
    Here in this case the OP may have a typo in the name of his test file. But in my case, I've a folder tests, and inside that, I've 2 files, routes.test.js and api.test.js. As OP told, if I run only one of the file, by removing the other, I get status of each tests inside that file. But if I have both of them for testing I'm only getting PASS status with Big letters, before the file name but status of each tests are not showing. – learner Jul 03 '20 at 09:52