Last active
September 11, 2016 20:29
-
-
Save CurtisHumphrey/cb8865bbdfb802bbe4fb to your computer and use it in GitHub Desktop.
Testing for styles using React, react-css-modules, and enzyme with chai-enzymes
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
import React from 'react' | |
import { | |
shallow, | |
render, | |
} from 'enzyme' | |
import _ from 'lodash' | |
import Component from './Component' | |
import stylesClass from './Component.scss' | |
// Step 1: this next line is important since the finders expect a '.' at the string start | |
const styles = _.mapValues(stylesClass, (raw) => '.' + raw) | |
describe('<Component />', () => { | |
it('should render style main by default', () => { | |
// Step 2: this is an html check so render is required | |
const wrapper = render(<Component />) | |
// Step 3: if you need to you can check on a particular node but often that just makes the test brittle | |
expect(wrapper).to.have.descendants(styles.main) | |
}) | |
it('should render style other by requested', () => { | |
// this is an html check so render is required | |
const wrapper = render(<DqButton other={true}/>) | |
// if you need to you can check on a particular node but often that just makes the test brittle | |
expect(wrapper).to.have.descendants(styles.other) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
AssertionError: expected the node in <??? /> to have descendants undefined
i got this error when try to use your example