In an app create with CRA v.1 I need to run a specific test file. How do I go about it? There is the --testPathIgnorePatterns
flag to add to the npm test
script to ignore a file or path but how do I run a particular test file with CRA from the command line?
In order to run a specific test, you'll need to use the jest command. npm test will not work. To access jest directly on the command line, install it via npm i -g jest-cli or yarn global add jest-cli . Then simply run your specific test with jest bar.
I have done this by using --
to pass custom arguments to the npm script.
Documentation on this option can be found here: https://docs.npmjs.com/cli/run-script
So, to run a single test in a create-react-app application, I run the following:
npm run test -- -t 'test-name'
Where test-name
is the value used in the describe function in jest -
describe('test-name', () => {
it('does something', () => { ... });
});
You can use the name of the file in the command, and it will run only it.
For example:
npm test src/components/App.test.js
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With