Last active
January 1, 2024 00:15
-
-
Save mmrko/288d159a55adf1916f71 to your computer and use it in GitHub Desktop.
Mocha & React & CSS Modules with Sass
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// setup.js | |
import hook from 'css-modules-require-hook' | |
import sass from 'node-sass' | |
hook({ | |
extensions: [ '.scss' ], | |
preprocessCss: data => sass.renderSync({ data }).css | |
}) | |
// component.js | |
import React from 'react' | |
import styles from './mocha-react-css-modules.scss' | |
export default class Component extends React.Component { | |
render() { | |
return <div className={ styles['some-class'] }>Hello</div> | |
} | |
} | |
// component.spec.js | |
import React from 'react/addons' | |
import { expect } from 'chai' | |
import Component from './component.js' | |
import styles from './mocha-react-css-modules.scss' | |
const TestUtils = React.addons.TestUtils | |
it('should have a valid CSS Modules class', () => { | |
const component = TestUtils.renderIntoDocument(<Component />) | |
const div = TestUtils.findRenderedDOMComponentWithTag(component, 'div') | |
expect(div.className).to.equal(styles['some-class']) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$black: '#aaa'; | |
.some-class { | |
color: $black; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mocha --require setup.js --compilers js:babel-core/register *.spec.js |
@janppires I had the same problem with you.Here is the solution: css-modules/css-modules-require-hook#64
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! I am getting an issue with scss partials. Any ideas on how to solve it?
where 'colors' is a scss partial file, named as '_colors.scss'.
My setup.js file looks like this:
thanks!