When getting into some basic React testing with CSS Modules I ran into one issue. How the hell do I test them?
You may see the issue that I faced requiring a
.css file, if you don’t let me show you.
1 2 3 4 5 6 7
So there isn’t really much to test here, but lets say we wanted to make sure that a
div had the disabled class when it was given a disabled prop.
We fire up our test, create it, babel compiles, but oh no,
MyCss is undefined, or an empty object. Well duh, we’re using Webpack to process our CSS.
For that matter we could use something to mock the import right? Yeah you could but lets introduce something even more awesome so we don’t have to create custom mocks.
Babel Plugin Webpack Loaders Awesomeness
Babel Plugin Webpack Loaders allows us to run our tests and process all requires through our typical webpack loaders.