Is there an option to show all test descriptions when I run jest tests?

ReactjsJestjsEnzymeCreate React-App

Reactjs Problem Overview


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).

Reactjs Solutions


Solution 1 - Reactjs

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.

Solution 2 - Reactjs

Note that, instead of

jest --verbose

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

// jest.config.js
module.exports = {
  ...
  verbose: true,
}

Solution 3 - Reactjs

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

Solution 4 - Reactjs

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"

Solution 5 - Reactjs

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSendaiView Question on Stackoverflow
Solution 1 - Reactjssudo bangbangView Answer on Stackoverflow
Solution 2 - ReactjsdansaliasView Answer on Stackoverflow
Solution 3 - ReactjsSteve VaughanView Answer on Stackoverflow
Solution 4 - ReactjsYamakage2077View Answer on Stackoverflow
Solution 5 - ReactjsprwinkmrView Answer on Stackoverflow