Last active
August 29, 2015 14:10
-
-
Save trotzig/c3190a694e047a4566e1 to your computer and use it in GitHub Desktop.
An example of the `subject` pattern for DRYer Jasmine specs
This file contains 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
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