140

I'm using jest and enzyme with my create-react-app project. When I run npm test, I get an output that shows the names of the test files that passed but I'd like the output to also include the names of the tests.

Example:

Button.test.js

it ('renders button', () => {
    const button = shallow(<Button type="save"/>);
    expect(toJson(button)).toMatchSnapshot();
});

Right now when I run npm test the output is just:

PASS src/Button.test.js"

and the number of passed and failed tests (when the tests are successful). I would like the output to include "renders button" and any other test descriptions (like how the output looks when an rspec test is run).

skyboyer
  • 22,209
  • 7
  • 57
  • 64
Sendai
  • 1,625
  • 2
  • 8
  • 14

5 Answers5

244

From Jest's command-line options docs

--verbose

Display individual test results with the test suite hierarchy.

So running

jest --verbose

Will print all the names in describe, it, test blocks.
If you're running tests with yarn, you can do

yarn test --verbose

If you're running tests with npm, you can do

npm test -- --verbose

If you want to make this default, change your test script in package.json

"test": "react-scripts test --env=jsdom --verbose",

Now both yarn test and npm test should show all test names.

Community
  • 1
  • 1
sudo bangbang
  • 27,127
  • 11
  • 75
  • 77
41

Note that, instead of

jest --verbose

you can also set verbose to true in jest.config.js:

// jest.config.js
module.exports = {
  ...
  verbose: true,
}
dansalias
  • 737
  • 6
  • 11
  • 1
    adding it to `jest.config.js ` is the only way to do it when using vue cli 4 and running `npm run test:unit` – ioan Apr 10 '20 at 15:19
28

The --verbose flag sounds like it might do what you are looking for. According to the docs, it displays individual test results.

Steve Vaughan
  • 2,163
  • 13
  • 18
  • 3
    i tried using this and the output doesn't appear to be any different – Sendai May 24 '18 at 18:01
  • What is the contents of your npm script and jest config? – Steve Vaughan May 24 '18 at 18:10
  • 12
    @Sendai remember to add two hyphens to escape from `npm` arguments to `jest` arguments - like so: `npm test -- --verbose`. (Otherwise, the `--verbose` argument goes to `npm`, and you're seeing verbose `npm` output rather than verbose `jest` output.) – mindplay.dk Oct 09 '19 at 19:11
  • You can also add this value for example `jest --verbose` for the key `test` in your **package.json** and run `npm run test` in your terminal. This also worked for me fine. – utkarsh-k Aug 11 '22 at 09:25
10

I was having the same issue with create-react-app (using both jest and enzyme), but was able to get the tests to appear after appending the existing test script in package.json with --verbose=true. So it now appears "test": "react-scripts test --env=jsdom --verbose=true"

Yamakage2077
  • 101
  • 3
4

after doing this configuration in package.json( "test": "react-scripts test --env=jsdom --verbose",) try running your test by npm test.

Note : with npm run test description is not reflecting for me as well.

Partho63
  • 3,117
  • 2
  • 21
  • 39
prwinkmr
  • 41
  • 2