-
-
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
CSS selectors match component props rather than rendered DOM #2560
Comments
In shallow, the wrapper is what's being rendered. In mount, the wrapper is the component itself - so that part isn't surprising. If your component renders a custom component with a className, using shallow, the selector would match it as well. What's the output of |
Here's the output of
|
As you can see, |
My main point of contention is that
So when we query for a CSS selector of |
It's not implied, though - because when working with enzyme wrappers, you're working with the component tree, not the final DOM that the browser sees (especially since one of the most important use cases of enzyme is testing server-rendering, where there's no DOM at all). I understand this is violating your personal expectations, but it's the way enzyme's always worked, quite intentionally. This confusion is why |
Fair enough. I do think this is weird behavior, but I can understand how enzyme is built around some assumptions that lead to this happening. |
Current behavior
Using CSS selectors for a class name will match a component with that value in a
className
prop, even if it's not in the output at all. For example:Surprisingly, this is not the case in
shallow
, justmount
.render
works correctly, as you might expect since it's parsing the HTML output.Expected behavior
I would expect CSS selectors to match against the rendered output, and to fail if a class name is not present in the HTML.
Your environment
node 14.19.1
API
Version
Adapter
The text was updated successfully, but these errors were encountered: