Description
Version
1.0.0-beta.29
Reproduction link
https://github.com/tkesgar/vue-jest-test-coverage
Steps to reproduce
The repro is a project created using @vue/cli with a component to be tested and its unit test. For coverage, I added babel-plugin-istanbul and nyc as described here. There are two code branches, one in the template using and one in the script tag (a conditional expression).
How to reproduce:
- Clone reproduction repo
yarn
yarn test:unit --coverage
What is expected?
Coverage should report at least two uncovered lines, one in the template via and one in the script.
What is actually happening?
Only one uncovered line is reported.
Example run:
yarn run v1.16.0
$ vue-cli-service test:unit --coverage
PASS tests/unit/TestComponent.spec.js
PASS tests/unit/example.spec.js
-----------------------------------------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-----------------------------------------------------|----------|----------|----------|----------|-------------------|
All files | 100 | 50 | 100 | 100 | |
vue-jest-test-coverage | 100 | 50 | 100 | 100 | |
unknown | 100 | 50 | 100 | 100 | 22 |
vue-jest-test-coverage/src/components/TestComponent | 100 | 50 | 100 | 100 | |
index.vue | 100 | 50 | 100 | 100 | 22 |
vue-jest-test-coverage/tests/unit | 100 | 100 | 100 | 100 | |
TestComponent.spec.js | 100 | 100 | 100 | 100 | |
example.spec.js | 100 | 100 | 100 | 100 | |
-----------------------------------------------------|----------|----------|----------|----------|-------------------|
Test Suites: 2 passed, 2 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 1.396s
Ran all test suites.
Done in 2.09s.
I am still relatively new into Vue, coming from React where code coverage works as expected. My guess is Vue internally converts the template into string during compilation phase, therefore template branching such as v-if cannot be detected.
I have looked for information on template coverage but I can't find any answer. Here is a number of links I discovered in forum: