Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
React Unit Test: Shallow Rendering
import React from 'react';
import expect from 'expect';
import ReactTestUtils from 'react-addons-test-utils';
export const NameComponent = ({ name }) => <span>Hello {name}!</span>;
describe('name component', () => {
it('should render the name', () => {
const renderer = ReactTestUtils.createRenderer();
renderer.render(<NameComponent name="foo" />);
const output = renderer.getRenderOutput();
expect(output.props.children).toEqual([ 'Hello ', 'foo', '!' ]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.