Open tkesgar opened 5 years ago
This is my first time doing Vue testing and this was one of my first doubts. It would be great to have some kind of coverage support in the templates.
Any suggestion about this? I have the same question.
which version of jest are you using? npm ls jest
?
if you're on v25, that might be the reason, see other issue: https://github.com/vuejs/vue-jest/issues/217, downgrade might be the best way to get around this without too much hassle
@ThePeach This is not an issue with the v25 of jest. Do not confuse the two.
This issue is about capturing the code coverage of <template>
blocks. The coverage of the Githubissues.
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:
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:
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: