Skip to content

Instantly share code, notes, and snippets.

@vvo

vvo/Button.js

Last active Oct 21, 2015
Embed
What would you like to do?
Shallow rendering example
import React from 'react';
import Label from './Label';
class Button extends React.Component {
render() {
return <div><Label name={this.props.name} /></div>;
}
}
export default Button;
import React from 'react';
class Label extends React.Component {
render() {
return <span>Hello {this.props.name}</span>;
}
}
export default Label;
import React from 'react';
import expect from 'expect';
import {createRenderer} from 'react-addons-test-utils';
import Button from './Button.js';
import Label from './Label.js';
describe('Button', () => {
it('works', () => {
let renderer = createRenderer();
renderer.render(<Button name="John" />);
let actualElement = renderer.getRenderOutput();
let expectedElement = <div><Label name="John" /></div>;
expect(actualElement).toEqual(expectedElement);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment