-
-
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
Fix Mount CSS prop selector for parity with Shallow #538
Fix Mount CSS prop selector for parity with Shallow #538
Conversation
Selector such as `Foo[bar="baz"]` previously would not return any components when rendering with `mount`. Resolves enzymejs#534
lgtm |
I think this is going to introduce similar issues as #377. I went a head and passed the props all the way down to the child div and the diff --git a/test/ReactWrapper-spec.jsx b/test/ReactWrapper-spec.jsx
index abb1aee..305f388 100644
--- a/test/ReactWrapper-spec.jsx
+++ b/test/ReactWrapper-spec.jsx
@@ -386,16 +386,16 @@ describeWithDOM('mount', () => {
it('should find React Component based on a components prop via css selector', () => {
class Foo extends React.Component {
- render() { return <div />; }
+ render() { return <div {...this.props} />; }
}
const wrapper = mount(
<div>
- <Foo bar="baz" />
+ <Foo role="button" />
</div>
);
- expect(wrapper.find('[bar]')).to.have.length(1);
- expect(wrapper.find('Foo[bar="baz"]')).to.have.length(1);
+ expect(wrapper.find('[role]')).to.have.length(1);
+ expect(wrapper.find('Foo[role="button"]')).to.have.length(1);
});
it('should not find components with invalid attributes', () => {
diff --git a/test/ShallowWrapper-spec.jsx b/test/ShallowWrapper-spec.jsx
index 6ec1331..5f2f753 100644
--- a/test/ShallowWrapper-spec.jsx
+++ b/test/ShallowWrapper-spec.jsx
@@ -483,16 +483,16 @@ describe('shallow', () => {
it('should find a React Component based on a components prop via css selector', () => {
class Foo extends React.Component {
- render() { return <div />; }
+ render() { return <div {...this.props} />; }
}
const wrapper = shallow(
<div>
- <Foo bar="baz" />
+ <Foo role="button" />
</div>
);
- expect(wrapper.find('[bar]')).to.have.length(1);
- expect(wrapper.find('Foo[bar="baz"]')).to.have.length(1);
+ 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', () => {
|
Seems like we have to choose between these two behaviors. I would say that returning |
Yeah, i'm with @aweary. I feel like that makes the most sense. If I feel like we should probably get some input from @ljharb / @lelandrichardson, but if we do take this, it seems like it should probably be a major change as it might break some peoples tests. |
Hi, team, Is there any updates on this? Thanks. |
If this would make existing tests that pass start to fail, then I think we need to have examples of those tests in master first - such that this PR has to change them to pass, making it semver-major. |
This bit me in writing one of my first Enzyme tests: I was expecting to find a child React node via a prop selector, and nothing matched :( This in spite of the documentation saying "Enzyme allows you to find components and nodes based on a subset of their properties". Newbie thought process: I expect (Regarding the number of items matched: since I'm used to |
I don't think this is relevant any more now that we're on v3. Can someone confirm? |
@ljharb that's correct, this isn't relevant. We don't use |
Selector such as
Foo[bar="baz"]
previously would not return any components when rendering withmount
.Resolves #534