Skip to content
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

SFC styles are not being applied to component in test environment with VTL #438

Open
joaopslins opened this issue Jan 13, 2022 · 5 comments

Comments

@joaopslins
Copy link

joaopslins commented Jan 13, 2022

Repository with reproduction: https://github.com/joaopslins/vue-sfc-styles-issue-repro

I'm using Vue 2 with Vue Testing Library

Using toBeVisible() matcher against an element with display: none; applied via a class in <styles> section does not work in my test. Since I couldn't find other people with the same issue (except this SO question where the author solved the issue by other means), I guess this is some configuration issue, or I must be doing something wrong.

I wasn't sure in which repo I should open this issue but I think VTL is working properly, so it must be something related to vue-jest. Unless I'm mistaken, I think vue-jest should apply the styles correctly, due to https://github.com/vuejs/vue-jest#supported-style-languages.

Component:
https://github.com/joaopslins/vue-sfc-styles-issue-repro/blob/8d1ac53921dcbe75d81eb3327d07ad9d650344d6/src/HelloWorld.vue#L1-L9

Test:
https://github.com/joaopslins/vue-sfc-styles-issue-repro/blob/8d1ac53921dcbe75d81eb3327d07ad9d650344d6/src/__tests__/HelloWorld.spec.js#L1-L13

This CodeSandbox makes me think it is possible though: https://codesandbox.io/s/vue-testing-sample-input-forked-drjsm?file=/src/components/Button.test.js

Relevant versions:
Node: 14
"jest": "^27.4.7",
"vue": "^2.6.11"
"@vue/vue2-jest": "^27.0.0-alpha.4",

@afontcu
Copy link
Member

afontcu commented Jan 14, 2022

Hi! And thank you for the report.

Looks like you might be right, because changing to inline styles makes the test pass (at least for me locally):

<template>
  <div class="test" style="display: none">Test!</div>
</template>

So it is def something about vue-jest's ability to compile the style block rather than a Vue Testing Library/Vue Test Utils/jest-dom issue.

I don't have the bandwidth right now to find the root cause, but submitting a PR with a failing test (probably here?) would help a ton 🙏 I'll look into it at some point.

Thanks!

@joaopslins
Copy link
Author

Hi @afontcu, I managed to get this PR #439, I'm not sure if this is the reproduction case you're looking for, so please let me know if there's something else that I can/should do, so I can improve the PR. Thanks again for your quick answer!

@afontcu
Copy link
Member

afontcu commented Jan 15, 2022

Hi! Looks like a good starting point, I'll take a look and see what I can come up with. Thanks!

@joaopslins
Copy link
Author

Awesome! Please let me know if I can help in other ways.

@maisasb
Copy link

maisasb commented Oct 19, 2022

Hi! Any news about this topic? I'm having the same issue here :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants