-
Notifications
You must be signed in to change notification settings - Fork 155
Support for CSS modules #38
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
Option B would be the best approach, I won't have time to implement it for a few weeks. Would you be able to make a PR? If not, we could do option A as a quick fix. |
I am off work for the coming week, would try a PR. |
Any updates? I'd love to help if needed. |
I just made a PR using option B.
;(function() {
var render = _Component.render
_Component.render = function(h) {
this['$style'] = {/* mock object */}
return render.call(this, h)
}
})() I don't know if there's a better way to do this. Let me know if there is.
|
Im populating my colors from scss variables and Im using in through this. $style, but for some reason this is not working when running unit tests in jest, through yarn serve all works fine. Any ideas? Am I doing smth wrong?
} Why am I doing this? Im using in couple of places colors in js and want to have it in one place. Currently Im just getting empty obj in jest and the object is populated normally when Im running the app. Is this valid use case @eddyerburgh ? |
Uh oh!
There was an error while loading. Please reload this page.
As the README states, this lib currently doesn't process the
<style>
parts.That's not a big issue when we unit test components that use the normal styles API, by which I mean they use harcoded class names in the template:
However, for CSS modules, this means that
this.$styles
is undefined in unit tests and rendering will fail.I think we have two options:
A: Mock
$styles
We could simply add this prop to a component if we find a
style
part with themodules
attribute, and use a Proxy to return the class that was required:Proxies are available in node since http://node.green/#ES2015-built-ins-Proxy, so that's quite good. We are dropping support for node 4.* in vue-cli etc. as well, so that should be enough.
The only downside I see it that we can't catch missing classes: If I mistype a class name in my component, I will still get back that mistyped classname from the proxy. If we properly evaluated the styles, we would get
undefined
and could catch this bug better, I think.B: Evaluating styles and building the $styles object.
We could add the usual popular preprocessors as peer deps, write a small wrapper for each to compile the styles, and then use something like string-extract-class-names to get all classnames from the resulting CSS.
From that, we could build a "real"
$styles
object and inject it into the component.@eddyerburgh - what approach would you prefer?
The text was updated successfully, but these errors were encountered: