Search code examples
vuejs2jestjsvue-cli-3

Vue Cli unit test with jest how to run single test


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.


Solution

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