I feel like this is a stupid question, but I can't find the answer anywhere.

Is there a way to run a single test file for a single Lightning Web Component.

I essentially want to be able to pass a filename when I run npm run test:unit so that only one test runs at a time instead of all my tests.

I have test:unit mapped to a script in my package.json file. Here is a snippet:

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "test:unit": "lwc-jest --verbose",
    "test:unit:log": "lwc-jest"

You can just pass e. g. a file name after your script name

E. g:

npm run test:unit mycomponent.test.js

Would all tests matching a file named mycomponent.test.js

  • 1
    I could have sworn I had tried that already and it didn't work. Oh well. Thanks for the quick and simple answer. – aaron Jun 17 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.