Read https://facebook.github.io/jest/docs/en/webpack.html to make webpack and Jest play nicely with CSS modules.
A Jest script processor that prevents CSS module parse errors.
npm install --save-dev jest-css-modules
Update your package.json file's jest
configuration:
{
"jest": {
"moduleNameMapper": {
"\\.(css)$": "<rootDir>/node_modules/jest-css-modules"
}
}
}
Now, imports such as import styles from './MyModule.css';
will pass through Jest without causing any pain.
Supports .css
, .less
, .scss
and .styl
extensions.