Vue Cli unit test with jest how to run single test

JimmyShoe picture JimmyShoe · Feb 27, 2019 · Viewed 9k times · Source

I have vue application using the vue cli 3. During the setup process i chose jest as the testing framework. To run my unit tests i have a script in the package.json:

test:unit": "vue-cli-service test:unit",

and to run this i write in the vs code terminal:

npm run test:unit

This runs all my tests that meet the specifications set up in the jest config section of the package.json file.

My question is how to run just a single test. Is there a specific command i need to run? or is there an vscode extension that will work with this setup.

Answer

Hardik Raval picture Hardik Raval · Oct 6, 2019

If you want to execute only single file then simply do:

npm run test:unit -t counter
OR
npm run test:unit counter

Whereas counter.spec.js is the my test file.