Skip to content
This repository has been archived by the owner on Mar 30, 2018. It is now read-only.

Commit

Permalink
fix the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sureshHARDIYA committed Mar 22, 2017
1 parent 04b9796 commit edd63a4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
9 changes: 3 additions & 6 deletions src/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,11 @@ export default class Dropdown extends Component {
onMouseLeave: mode === 'hover' && handleMouseLeave,
}

if (typeof this.props.children === 'function') {
return this.props.children({ isOpen, ...eventHandlers })
if (typeof children === 'function') {
return children({ isOpen, ...eventHandlers })
}

if (!Array.isArray(children) || children.length !== 2) {
return new Error('Children must be passed as array and must have two components.')
}
const [target, body] = this.props.children
const [target, body] = children

// construct target Element
const targetElement = cloneElement(target, {
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/Dropdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ it('closes when clicked when in hover mode', () => {
expect(component.getInstance().state.isOpen).toBe(false)
})

it('it should throw error on invalid children', () => {
it('it should throw Invalid proptytype error on invalid children', () => {
expect(() => {
const component = renderer.create(
<Dropdown mode="hover">
{[<Button key="button">Hover</Button>]}
<Button key="button">Hover</Button>
</Dropdown>
)
component.toJSON()
Expand Down
5 changes: 4 additions & 1 deletion src/__tests__/__snapshots__/Dropdown-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,10 @@ exports[`it should render correctly when children are passed as function 1`] = `
</div>
`;

exports[`it should throw error on invalid children 1`] = `"Dropdown.render(): A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object."`;
exports[`it should throw Invalid proptytype error on invalid children 1`] = `
"Warning: Failed prop type: Invalid prop \`children\` supplied to \`Dropdown\`.
in Dropdown"
`;

exports[`renders correctly 1`] = `
<div
Expand Down

0 comments on commit edd63a4

Please sign in to comment.