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.
Run the unit tests for a Vue project. Utilize the beforeEach() and afterEach() functions within a unit test suite. Write unit tests for testing the implementation details of a Vue component.
createLocalVue returns a Vue class for you to add components, mixins and install plugins without polluting the global Vue class. The errorHandler option can be used to handle uncaught errors during component render function and watchers.
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.
The Vue CLI service respects Jest's CLI options, so you can append them to commands in package.json
, e.g
{ ... "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build", "test:unit": "vue-cli-service test:unit", "test:only": "vue-cli-service test:unit --testPathPattern=user.store", }, "dependencies": {
testPathPattern
takes a regex which applies to the spec file names, so in my tests if I specify the pattern
--testPathPattern=user.store
I run a single spec file, but if I specify
--testPathPattern=store
I run multiple matching spec files with store
in the name.
Here is the Jest docs ref
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