1

I have tried this answer to get coverage for a single component but it is not working. The test runs only for that component but no coverage?

Is there some other configuration that needs to be done anywhere?

I have tried:

npm test src/components/component1/my-component.test.tsx --coverage --collectCoverageFrom=src/components/component1/my-component.test.tsx

Anything I am doing wrong?

Sole
  • 3,100
  • 14
  • 58
  • 112

2 Answers2

0

The collectCoverageFrom takes in glob patterns as argument, so you need adjust that path string with "".

I have successfully run this command with code coverage from one file with

node_modules/.bin/jest ComponentTest.test.ts --coverage --collectCoverageFrom="path/Component.tsx"

It also it may be that your "test" cmd you are running from package.json is obscuring the additional arguments, try directly calling jest from modules to see if thats the case.

Luke Celitan
  • 322
  • 1
  • 11
0

This worked to me with create-react-app from windows cmd:

npx react-scripts test src/components/common/__test__/Dropdown.test.tsx --coverage --collectCoverageFrom=src/components/common/Dropdown.tsx
Eqzt111
  • 487
  • 6
  • 17