-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TASK: Integrate the test utility package for stateless pure react com…
…ponents #18
- Loading branch information
1 parent
332bd45
commit 5959380
Showing
4 changed files
with
52 additions
and
16 deletions.
There are no files selected for viewing
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
51 changes: 37 additions & 14 deletions
51
Resources/Private/JavaScript/Host/Components/Button/index.spec.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,51 @@ | ||
import React from 'react'; | ||
import chai from 'chai'; | ||
import TestUtils from 'react-addons-test-utils'; | ||
import {shallowRender} from 'skin-deep'; | ||
import Button from './index.js'; | ||
|
||
const expect = chai.expect; | ||
const {expect} = chai; | ||
|
||
function renderTree(props) { | ||
return shallowRender( | ||
<Button {...props}> | ||
My button text | ||
</Button> | ||
); | ||
} | ||
|
||
describe('Button Component', () => { | ||
let renderer; | ||
it('should render a `<button>` element and the passed text as the label.', () => { | ||
const tree = renderTree({ | ||
isFocused: false, | ||
isDisabled: false, | ||
style: 'clean', | ||
hoverStyle: 'clean', | ||
onClick: () => null | ||
}); | ||
|
||
beforeEach(() => { | ||
renderer = TestUtils.createRenderer(); | ||
expect(tree.getRenderOutput().type).to.equal('button'); | ||
expect(tree.text()).to.equal('My button text'); | ||
}); | ||
|
||
it('should render a button element and the passed children.', () => { | ||
const onClickHandler = () => null; | ||
it('should add the `disabled` attribute to the `<button>` node if the `isDisabled` prop was passed as `true`.', () => { | ||
const disabledTree = renderTree({ | ||
isFocused: false, | ||
isDisabled: true, | ||
style: 'clean', | ||
hoverStyle: 'clean', | ||
onClick: () => null | ||
}); | ||
|
||
renderer.render( | ||
<Button isFocused={false} isDisabled={false} style="clean" hoverStyle="clean" onClick={onClickHandler}> | ||
"test" | ||
</Button> | ||
); | ||
expect(disabledTree.toString().indexOf('disabled') > -1).to.equal(true); | ||
|
||
const actualElement = renderer.getRenderOutput(); | ||
const tree = renderTree({ | ||
isFocused: false, | ||
isDisabled: false, | ||
style: 'clean', | ||
hoverStyle: 'clean', | ||
onClick: () => null | ||
}); | ||
|
||
expect(actualElement.type).to.equal('button'); | ||
expect(tree.toString().indexOf('disabled') > -1).to.equal(false); | ||
}); | ||
}); |
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
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