Skip to content
This repository has been archived by the owner on Aug 29, 2021. It is now read-only.

Commit

Permalink
Merge pull request #22 from afhammad/fix-single-clause-component
Browse files Browse the repository at this point in the history
fix rendering of single clause when using components
  • Loading branch information
stoeffel committed Nov 8, 2015
2 parents c63c9e7 + 1326df4 commit 38fdfdc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions __tests__/component-test.js
Expand Up @@ -11,6 +11,18 @@ const {
} = require('../module/');
describe('React-Cond components', () => {

it('should render the child component for a single condition if it matches', () => {
const isTrue = (i) => i;

let component = TestUtils.renderIntoDocument(
<Cond value={true}>
<Clause test={isTrue}><h1>Works!</h1></Clause>
</Cond>
);
let val = TestUtils.findRenderedDOMComponentWithTag(component, 'h1');
equal(val.getDOMNode().textContent, 'Works!');
});

it('should render the child component if the condition value is equal to `props.value`', () => {
let component = TestUtils.renderIntoDocument(
<Cond value={1}>
Expand Down
4 changes: 4 additions & 0 deletions module/index.js
Expand Up @@ -34,7 +34,11 @@ export const Cond = React.createClass({
if (Array.isArray(children[0])) {
clauses = children;
} else if (children[0] && children[0].props && children[0].props[CASE_SYMBOL]) {
// multiple clauses
clauses = children.map(c => [c.props.test, c.props.children]);
} else if (children && children.props && children.props[CASE_SYMBOL]) {
// single clause
clauses = [[children.props.test, children.props.children]];
} else {
clauses = [children];
}
Expand Down

0 comments on commit 38fdfdc

Please sign in to comment.