0

I trying to do unit testing in a react application in which I want to test only one component.

What is the command for running the test of particular component?

I am doing this way for testing.

npm test -- --testPathPattern components

I have all the *.test.js inside the components folder.

Above command will run the test cases for all the test files under the components folder but I want to run the tests only for the specific component.

2
  • 3
    If you're using vscode, you can install jest runner extension, after that you can easily run a single test or a test suite (when you have your test file open, it'd show debug and run commands on top of test case declaration). Plus it'll show you in its integrated terminal, the command it's running. Commented Oct 3, 2020 at 11:34
  • That's a good idea. I'll follow up on this. Its jest runner extension right? Commented Oct 3, 2020 at 11:40

2 Answers 2

2

You can use the below command for testing only one component (file_name.test.js in below example)

npm test src/components/file_name.test.js

OR in a simple way,

npm test -- file_name.test.js

Both commands will work. There are more ways for unit testing of an individual component. You can find it here.

npm test -- --help
Sign up to request clarification or add additional context in comments.

Comments

0

testing only one component

npm t -- filename.ts or js

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.