Skip to content

Commit

Permalink
Merge pull request #257 from poluyanov/stateless
Browse files Browse the repository at this point in the history
Fix children() for stateless children
  • Loading branch information
lelandrichardson committed Mar 15, 2016
2 parents 37f6e5d + 1b6fd8c commit be08a61
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/MountedTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ export function childrenOfInstInternal(inst) {
if (REACT013 && !renderedChildren[key].getPublicInstance) {
continue;
}
if (!REACT013 && typeof renderedChildren[key]._currentElement.type === 'function') {
children.push(renderedChildren[key]._instance);
continue;
}
children.push(renderedChildren[key].getPublicInstance());
}
return children;
Expand Down
17 changes: 17 additions & 0 deletions test/ReactWrapper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,23 @@ describeWithDOM('mount', () => {
expect(wrapper.find('.bar')).to.have.length(1);
expect(wrapper.find('.qoo').text()).to.equal('qux');
});

it('works with nested stateless', () => {
const TestItem = (props) => (
<div className="item">1</div>
);
const Test = (props) => (
<div className="box">
<TestItem test="123"/>
<TestItem/>
<TestItem/>
</div>
);
const wrapper = mount(<Test />);
const children = wrapper.find('.box').children();
expect(children).to.have.length(3);
expect(children.at(0).props().test).to.equal('123');
})
});

describe('.contains(node)', () => {
Expand Down

0 comments on commit be08a61

Please sign in to comment.