-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vue SFC template coverage #198
Comments
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? |
@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 In the v25 jest issue, it does not capture the code coverage of any .vue files (or other non-.js files). |
@ThePeach This issue refers to the coverage of the |
sorry! misread! |
@tkesgar did you manage to make any progress on this? Also curious whether this is possible |
So far still no. Thankfully it is just a minor inconvenience; with carefully written test set it should be covered anyway (e.g. I'm taking a wild guess here: I don't think it is possible with templates. Maybe it will be possible with JSX (using |
Hope it's okay to bump this thread, because it's a frustration that I run into with Vue's test coverage coming from React and JSX. And this was the most relevant and recent discussion on this I could find. It's nice to see the actual HTML that's covered, and I have yet to see a way to do this with Vue. This results in a lot of false coverage reporting in our app. A very basic example SFC:
And the type of very simple snapshot test that I had grown accustomed to in React:
The coverage report told me I have everything under control: But it's not actually the case. The Random React/JSX example I grabbed from the internet: I know you said in your most recent comment it's only a minor inconvenience, but I think you're letting them off the hook a bit here. For all of these dev problems that are simply resolved by being a little more careful, there are 100 npm modules available to patch that particular hole in our brains. 😄 And it's odd how little discussion I've seen on this one in particular, but maybe I'm just not very good at searching the internet for Vue issues yet. Thank you for coming to my TED Talk! 😅 |
Any news on this? |
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:
The text was updated successfully, but these errors were encountered: