Skip to content
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

Merged
merged 4 commits into from
Mar 9, 2016

Conversation

iancmyers
Copy link
Contributor

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.

@@ -124,7 +133,7 @@ export function childrenOfInstInternal(inst) {
}
return children;
} else if (
REACT014 &&
(!REACT013) &&
Copy link
Member

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

@lencioni
Copy link
Contributor

lencioni commented Mar 9, 2016

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\$/));
Copy link
Collaborator

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.

@lelandrichardson
Copy link
Collaborator

wow, this is great! Thanks for working on this.

@iancmyers
Copy link
Contributor Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/14/15?

} from './version';

function internalInstanceKey(node) {
return Object.keys(node).filter(key => key.match(/^__reactInternalInstance\$/))[0];
Copy link
Member

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.
@ljharb
Copy link
Member

ljharb commented Mar 9, 2016

LGTM 👍

lelandrichardson added a commit that referenced this pull request Mar 9, 2016
Add compatibility for React 15 RC1
@lelandrichardson lelandrichardson merged commit 3ed3632 into enzymejs:master Mar 9, 2016
} from './version';

function internalInstanceKey(node) {
return Object.keys(Object(node)).filter(key => key.match(/^__reactInternalInstance\$/))[0];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really?

cartoon drawing of a sad fox

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accessible is public, Ben. ¯\_(ツ)_/¯

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).

Copy link
Member

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants