Skip to content

Commit

Permalink
[Fix] mount: ensure that react-text comment nodes don’t break `.f…
Browse files Browse the repository at this point in the history
…ind`

 - add `shallow` test just in case
 - use `values` over `Object.keys` in MountedTraversal

Fixes #689.
  • Loading branch information
ljharb committed Nov 17, 2016
1 parent 08f2f77 commit 8db9f23
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/MountedTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ export function childrenOfInstInternal(inst) {
if (!REACT013 && typeof node._currentElement.type === 'function') {
return node._instance;
}
if (typeof node._stringText === 'string') {
return node;
}
return node.getPublicInstance();
});
} else if (
Expand Down Expand Up @@ -253,9 +256,7 @@ function findAllInRenderedTreeInternal(inst, test) {
}
return true;
}).forEach((node) => {
ret = ret.concat(
findAllInRenderedTreeInternal(node, test),
);
ret = ret.concat(findAllInRenderedTreeInternal(node, test));
});
} else if (
!REACT013 &&
Expand Down
18 changes: 18 additions & 0 deletions test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,25 @@ describeWithDOM('mount', () => {

expect(wrapper.find('span[htmlFor="foo"]')).to.have.length(1);
expect(wrapper.find('span[htmlFor]')).to.have.length(1);
});

it('works with an adjacent sibling selector', () => {
const a = 'some';
const b = 'text';
const wrapper = mount(
<div>
<div className="row">
{a}
{b}
</div>
<div className="row">
{a}
{b}
</div>
</div>,
);
expect(wrapper.find('.row')).to.have.lengthOf(2);
expect(wrapper.find('.row + .row')).to.have.lengthOf(1);
});

// React 15.2 warns when setting a non valid prop to an DOM element
Expand Down
19 changes: 19 additions & 0 deletions test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,25 @@ describe('shallow', () => {
expect(wrapper.find('[title]')).to.have.length(1);
});

it('works with an adjacent sibling selector', () => {
const a = 'some';
const b = 'text';
const wrapper = shallow(
<div>
<div className="row">
{a}
{b}
</div>
<div className="row">
{a}
{b}
</div>
</div>,
);
expect(wrapper.find('.row')).to.have.lengthOf(2);
expect(wrapper.find('.row + .row')).to.have.lengthOf(1);
});

it('should error sensibly if prop selector without quotes', () => {
const wrapper = shallow(
<div>
Expand Down

0 comments on commit 8db9f23

Please sign in to comment.