-
-
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
Add compatibility for React 15 RC1 #240
Add compatibility for React 15 RC1 #240
Conversation
@@ -124,7 +133,7 @@ export function childrenOfInstInternal(inst) { | |||
} | |||
return children; | |||
} else if ( | |||
REACT014 && | |||
(!REACT013) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nbd, but i don't think we need parens around !foo
here or elsewhere
LGTM |
@@ -17,6 +17,13 @@ export function propsOfNode(node) { | |||
if (node && node._reactInternalComponent && node._reactInternalComponent._currentElement) { | |||
return (node._reactInternalComponent._currentElement.props) || {}; | |||
} | |||
if (REACT15 && node) { | |||
const instanceKey = Object.keys(node).find(key => key.match(/^__reactInternalInstance\$/)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we're doing this in more than one place, it's probably best if we pull this out into a helper method that also makes it more semantically clear.
wow, this is great! Thanks for working on this. |
9d6e3cf
to
248fd9c
Compare
I've updated this PR to address all of the feedback. |
@@ -11,3 +11,7 @@ fi | |||
if [ "$REACT" = "0.14" ]; then | |||
npm run react:14 | |||
fi | |||
|
|||
if [ "$REACT" = "15" ]; then | |||
npm run react:14 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/14/15
?
248fd9c
to
eda2a27
Compare
} from './version'; | ||
|
||
function internalInstanceKey(node) { | ||
return Object.keys(node).filter(key => key.match(/^__reactInternalInstance\$/))[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per https://travis-ci.org/airbnb/enzyme/jobs/114854317 - pre-ES6, Object.keys
throws on primitive values. You can either use the object-keys
module, or do Object.keys(Object(node))
(but that runs decently slower).
This adds compatibility for React 15 RC1. The most painful/icky change is in retrieving the internal instance, which has a random number appended to its key. There's also a hack to work around a bug in React 15 where warnings on ref and key are throwing for nodes with string types.
eda2a27
to
650c83a
Compare
LGTM 👍 |
Add compatibility for React 15 RC1
} from './version'; | ||
|
||
function internalInstanceKey(node) { | ||
return Object.keys(Object(node)).filter(key => key.match(/^__reactInternalInstance\$/))[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accessible is public, Ben. ¯\_(ツ)_/¯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next time I'm making it nonenumerable and monkey-patching Object.getOwnPropertyNames (and Reflect.ownKeys I guess).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@spicyj also every goPD and ownKeys in every realm that i could possibly create!
This adds compatibility for React 15 RC1. The most painful/icky change is in retrieving the internal instance, which has a random number appended to its key.
There's also a hack to work around a bug in React 15 where warnings on ref and key are throwing for nodes with string types.