Skip to content

Instantly share code, notes, and snippets.

@StevenLangbroek
Last active December 4, 2015 11:15
Show Gist options
  • Save StevenLangbroek/d939e09266b47fdc9618 to your computer and use it in GitHub Desktop.
Save StevenLangbroek/d939e09266b47fdc9618 to your computer and use it in GitHub Desktop.
Render Helper for React
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
}
}
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