-
-
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
.key() isn't consistent with unwrapped element .key #1488
Comments
It seems like this could be addressed by changing all the If you'd like to write a PR that attempts to fix this (especially if it maintains consistency across the adapter versions), I'd love to review it. |
Can't the fix just be isolated to the |
@bdwain that seems like it might work. Want to try out a PR? |
yea i can do it. |
made #1536 |
Current behavior
If a
key
is not specified on an element, Enzyme returnsundefined
from.key()
Expected behavior
I would expect
.key()
to returnnull
the same as React does for.key
on an (unwrapped) element.Contrived example: https://codesandbox.io/s/xpj8pvpj2o
My use case is that I'm writing a test for a library that ensures that an element generated from a shorthand prop (on a parent) matches a specific factory-generated counterpart. Part of this process involves the optional generation of a key, so I need to check that the keys match (which isn't covered by
.contains()
or similar).As you can see from the example, the assertion works fine when a key is provided/expected, but breaks when it isn't. There are easy workarounds:
.get()
to retrieve the unwrapped element...but I thought I'd bring it up anyway.
Your environment
API
Version
Adapter
The text was updated successfully, but these errors were encountered: