-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Selecting React Components via CSS prop selector #534
Comments
selectors should always have parity between mount and shallow. So no, it would not be intentional. If I had to guess, it's the first selector that is failing? |
@blainekasten @travisperson I've reproduced the issue here: enzyme-test-repo/blob/issue-534/test.js class Foo extends React.Component {
render() {
return <div />
}
}
describe('CSS selector parity', () => {
it('should work with mount', () => {
const wrapper = mount(
<div>
<Foo bar='baz' />
</div>
);
expect(wrapper.find('Foo[bar="baz"]')).to.have.length(1);
});
it('should work with shallow', () => {
const wrapper = shallow(
<div>
<Foo bar='baz' />
</div>
);
expect(wrapper.find('Foo[bar="baz"]')).to.have.length(1);
});
}) I tested with enzyme 2.2 - latest and it failed in all versions, so this doesn't appear to be a regression. |
@blainekasten so the issue is that export function instHasProperty(inst, propKey, stringifiedPropValue) {
if (!isDOMComponent(inst)) return false;
... These same checks aren't done in the corresponding |
Well, if it's any indication: I just commented that line out and ran the tests. 😕 T h e y A l l P a s s e d 😕 |
Also, really great investigation work @aweary ! :hattip: |
The line as added during the PR for the feature. @blainekasten you might be able to pull some context out of the discussion, but I'd assume it may of just slipped by during the churn for on exactly how the selectors should work? I did not see any comments in the PR related to line. https://github.com/airbnb/enzyme/pull/70/files#diff-077191fec7d029ff150ed4dfafc6a732R73 The original commit that the line was added in on (prior to the rebase) 2132d4e (first commit in the chain prior to rebase e5a035d if you want to back track and explore the history of the PR) |
I believe it was likely because the other selector methods |
Awesome. Sounds like a really easy fix. @travisperson would you be interested in submitting a PR for this? Just remove that one line and include some tests that would fail without the change. |
Selector such as `Foo[bar="baz"]` previously would not return any components when rendered with Mount. Resolves enzymejs#534
Selector such as `Foo[bar="baz"]` previously would not return any components when rendering with `mount`. Resolves enzymejs#534
Is this finished? What is left to do? Can I give it a go? Happy #hacktoberfest! |
Sort of, there is a PR #538, but I'm not sure if the exact before has been settled on. There is a bit more information in the PR. |
Closed by enzyme v3 |
I was looking at this yesterday and it appears that when using
mount
you can't use CSS prop selectors. I did some digging and found the PR (#70), and after reading through it a bit it appears that it was inertial. Instead of using a string (via CSS prop selector), the go to method was to instead use the object selector. At this point I stopped digging and assumed that the CSS prop selector was not supported in this way. However, when shallow rendering you can use a CSS prop selector with a React Component.Is this intentional for shallow but not for mount?
The text was updated successfully, but these errors were encountered: