Skip to content

Commit

Permalink
Fix Mount CSS prop selector for parity with Shallow
Browse files Browse the repository at this point in the history
Selector such as `Foo[bar="baz"]` previously would not return any
components when rendering with `mount`.

Resolves enzymejs#534
  • Loading branch information
Travis Person committed Aug 11, 2016
1 parent aaca837 commit 5b13cdf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/MountedTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export function instHasType(inst, type) {
}

export function instHasProperty(inst, propKey, stringifiedPropValue) {
if (!isDOMComponent(inst)) return false;
const node = getNode(inst);
const nodeProps = propsOfNode(node);
const descriptor = Object.getOwnPropertyDescriptor(nodeProps, propKey);
Expand Down
14 changes: 14 additions & 0 deletions test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,20 @@ describeWithDOM('mount', () => {

});

it('should find React Component based on a components prop via css selector', () => {
class Foo extends React.Component {
render() { return <div />; }
}
const wrapper = mount(
<div>
<Foo bar="baz" />
</div>
);

expect(wrapper.find('[bar]')).to.have.length(1);
expect(wrapper.find('Foo[bar="baz"]')).to.have.length(1);
});

it('should not find components with invalid attributes', () => {
// Invalid attributes aren't valid JSX, so manual instantiation is necessary
const wrapper = mount(
Expand Down
14 changes: 14 additions & 0 deletions test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,20 @@ describe('shallow', () => {
expect(wrapper.find('[data-foo]')).to.have.length(1);
});

it('should find a React Component based on a components prop via css selector', () => {
class Foo extends React.Component {
render() { return <div />; }
}
const wrapper = shallow(
<div>
<Foo bar="baz" />
</div>
);

expect(wrapper.find('[bar]')).to.have.length(1);
expect(wrapper.find('Foo[bar="baz"]')).to.have.length(1);
});

it('should find components with multiple matching react props', () => {
function noop() {}
const wrapper = shallow(
Expand Down

0 comments on commit 5b13cdf

Please sign in to comment.