-
Notifications
You must be signed in to change notification settings - Fork 266
Feature request: Support for testing v-bind() in scoped CSS? #1931
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
Comments
Hi @oasjohn I think the support for CSS is not great at the moment, we also had issues like #1704 Are you using jsdom or happy-dom? Sometimes jsdom gives better results. But, AFAIK, we don't have tests that check v-bind in VTU, so maybe this doesn't work at all. Can you provide us a small repro online using https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/vue?initialPath=__vitest__ ? We'll try to take a loook |
Thanks - I worked up a super simple example here |
Thanks. I don't see the failing test though? Can you also remove the other components and tests that we don't need to keep the repro focused on the issue? |
Ah, I've cleaned it out a bit. |
Just digging into this some more, I'm wondering if CSS, and in particular Scoped Styles are even calculated when a component is mounted within vue-test-utils. I was going to try accessing the expected attributes directly, or use getComputedStyle to see what the resultant rules were after applying all classes, but there's no inline style data rendered as expected. For example, if you have a custom label with the following template:
And in the SFC, a scoped style such as...
This is what should be rendered (xyz123 is just the hash Vue assigns):
However, when I log out the HTML from the wrapper within a test, this is what I get:
|
Ok, so I dug a bit into this, and it turns out vitest use the cjs build of vue, which does nothing for By changing the vitest config to force the usage of Vue ESM packages, the issue goes away:
I made a very simple repro here if you want to take a look. This might be related to how Vue declares its various formats, but I'm far from being an expert on this (see vuejs/core#4814 ) Anyway, I don't we need to do anything special in VTU, as it seems to work 👍 |
Thanks, I'll give that a spin. |
Worked like a charm. Thanks so much! |
PROBLEM
I'm utilizing v-bind() in scoped CSS classes, to apply style rules to component instances based on reactive properties. I'm able to use wrapper.classes('foo') to locate classes that have been applied, but cannot seem to find a way to write a test that verifies that the v-bind has properly applied the updated rules.
Is there a different approach I should be taking, or is there a way to parse the CSS class rules within test-utils without having to write something lower level?
The text was updated successfully, but these errors were encountered: