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