New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP][web] Add tests for UI components #2327

Merged
merged 11 commits into from May 15, 2017

[web] Add tests for js/components/common/ToggleButton.jsx

  • Loading branch information...
MatthewShao committed May 12, 2017
commit 2b5a300284b3b15c08f51f0aa3948c1f6465929f
@@ -0,0 +1,26 @@
import React from 'react'
import renderer from 'react-test-renderer'
import ToggleButton from '../../../components/common/ToggleButton'
describe('ToggleButton Component', () => {
let mockFunc = jest.fn()
it('should render correctly', () => {
let checkedButton = renderer.create(
<ToggleButton checked={true} onToggle={mockFunc} text="foo">
text
</ToggleButton>),
tree = checkedButton.toJSON()
expect(tree).toMatchSnapshot()
})
it('should handle click action', () => {
let uncheckButton = renderer.create(
<ToggleButton checked={false} onToggle={mockFunc} text="foo">
text
</ToggleButton>),
tree = uncheckButton.toJSON()
tree.props.onClick()
expect(mockFunc).toBeCalled()
})
})
@@ -0,0 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`ToggleButton Component should render correctly 1`] = `
<div
className="btn btn-toggle btn-primary"
onClick={[Function]}
>
<i
className="fa fa-fw fa-check-square-o"
/>
 
foo
</div>
`;
ProTip! Use n and p to navigate between commits in a pull request.