Skip to content

Instantly share code, notes, and snippets.

@trotzig
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trotzig/c3190a694e047a4566e1 to your computer and use it in GitHub Desktop.
Save trotzig/c3190a694e047a4566e1 to your computer and use it in GitHub Desktop.
An example of the `subject` pattern for DRYer Jasmine specs
describe('Button', () => {
beforeEach(() => {
this.subject = () => {
return React.addons.TestUtils.renderIntoDocument(
<Button {...this.props} />
);
};
});
describe('with a `text` prop', => {
beforeEach(() => this.props = { text: 'Click me'});
it('renders the text', () => {
expect(this.subject()).toHaveText('Click me');
});
describe('and an `icon` prop', () => {
beforeEach(() => this.props.icon = 'email');
it('renders the icon', () => {
expect(this.subject()).toHaveIcon('email');
});
it('renders the text', () => {
expect(this.subject()).toHaveText('Click me');
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment