Shrikant Dande
Shrikant Dande

Reputation: 233

Coverage report for jest unit tests not displaying with --coverage option

My Project is based on Create-react-app setup and my package.json script for testing unit tests is as below

"scripts": {
    "test": "react-scripts test --coverage",
 }

or

 "test": "react-scripts test --coverage --collectCoverageFrom=src/**/*.{js,jsx}

It executes tests in Test folder but doesn't display coverage report.Can you help to solve this issue. enter image description here

My file structure is as below src | --- Test ---components> moduleA > package1 > package2> transaction.js, abcd.js... etc

ProcessEvent.test.js

describe('ProcessEvent Component', () => {

    const expectedProps = {
        "event": {iconStatus:'active', desc:'abc'}
    }

    it('should render without error', () => {
        const component = <ProcessEvent {...expectedProps}/>
        const wrapper = component.find('.eventclass');
        expect(wrapper.length).toBe(1);
    });

    it('should receive valid props', () => {
        const component = shallow(<ProcessEvent {...expectedProps}/>);
        const wrapper = component.find('.eventclass');
        expect(component.props).toBeDefined();
    });

});

Upvotes: 4

Views: 3278

Answers (1)

Sujit Y. Kulkarni
Sujit Y. Kulkarni

Reputation: 1386

Using --watchAll=false parameter makes it list down all the files.

Example package.json

{
...
"scripts": {
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test",
    "coverage": "react-app-rewired test -- --coverage --watchAll=false",
    "eject": "react-scripts eject",
    "serve": "node server.js"
  },
...
}

Also your coverage report is physically located at /coverage/lcov-report. Opening an index.html located there, would show you the coverage report in your browser.

Upvotes: 2

Related Questions