Skip to content

Commit

Permalink
[Fix] mount: children: include text nodes
Browse files Browse the repository at this point in the history
Fixes #2265.
  • Loading branch information
ljharb committed Oct 25, 2019
1 parent f192110 commit 8e2d65c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions packages/enzyme-test-suite/test/shared/methods/children.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ export default function describeChildren({
expect(wrapper.children()).to.have.lengthOf(0);
});

it('includes text nodes', () => {
const wrapper = Wrap(<div>B<span />C</div>).children();
expect(wrapper).to.have.lengthOf(3);
});

it('does not attempt to get an instance for text nodes', () => {
const wrapper = WrapRendered(<div>B<span />C</div>);
expect(wrapper).to.have.lengthOf(1);
expect(wrapper).to.have.lengthOf(isShallow ? 1 : 3);
});

it('skips the falsy children', () => {
Expand Down Expand Up @@ -194,13 +199,13 @@ export default function describeChildren({
foo
</div>
</span>`,
...(isShallow ? [' '] : []),
' ',
`<span>
<div>
bar
</div>
</span>`,
...(isShallow ? [' '] : []),
' ',
`<span>
<div>
baz
Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme/src/ReactWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ class ReactWrapper {
* @returns {ReactWrapper}
*/
children(selector) {
const allChildren = this.flatMap((n) => childrenOfNode(n.getNodeInternal()).filter((x) => typeof x === 'object'));
const allChildren = this.flatMap((n) => childrenOfNode(n.getNodeInternal()));
return selector ? allChildren.filter(selector) : allChildren;
}

Expand Down

0 comments on commit 8e2d65c

Please sign in to comment.