Last active
December 4, 2015 11:15
-
-
Save StevenLangbroek/d939e09266b47fdc9618 to your computer and use it in GitHub Desktop.
Render Helper for React
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
| import React from 'react'; | |
| import { renderIntoDocument } from 'react-addons-test-utils'; | |
| import { findDOMNode } from 'react-dom'; | |
| /** | |
| * This is a higher order function, which creates a renderer | |
| * for a specified component. You call the resulting function with `props`, | |
| * and in return get an object containing the rendered component as | |
| * well as the props that were passed in initially. | |
| */ | |
| export default Component => props => { | |
| const component = renderIntoDocument( | |
| <Component {...props} /> | |
| ); | |
| return { | |
| output: findDOMNode(component), | |
| component, | |
| props | |
| } | |
| } |
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
| import Icon from './'; | |
| import createRenderer from 'utilities/createRenderer'; | |
| const render = createRenderer(Icon); | |
| describe('Component: Icon', () => { | |
| it('has the correct attributes', () => { | |
| const { output } = render({ | |
| lowResSrc, | |
| highResSrc, | |
| placeholderSrc, | |
| initialSrc | |
| }); | |
| const subject = output.getAttribute('class'); | |
| const expectation = 'icon'; | |
| expect(subject).to.equal(expectation); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment