-
-
Save eigenmannmartin/7da3e7a567e97fc63ba2505df18abc65 to your computer and use it in GitHub Desktop.
Mocha & React & CSS Modules
This file contains 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 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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment