Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Mount CSS prop selector for parity with Shallow #538

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {...this.props} />; }
}
const wrapper = mount(
<div>
<Foo role="button" />
</div>
);

expect(wrapper.find('[role]')).to.have.length(2);
expect(wrapper.find('Foo[role="button"]')).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 {...this.props} />; }
}
const wrapper = shallow(
<div>
<Foo role="button" />
</div>
);

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

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