-
-
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
Support React 16 #928
Comments
+1 |
Generally we've supported RCs, but not alphas. That seems like the appropriate place to draw the line. |
React native 0.44 (actual release, not alpha/beta/rc) requires react 16 alpha. |
I have to admit the situation is a bit special: last 2 stable react-native version use react@16 alpha. Maybe we should reconsider where is "the line". In my case, I am having the following issue: TypeError: window.addEventListener is not a function
at Object.<anonymous> (node_modules/react-dom/lib/ReactDOMFrameScheduling.js:71:10)
at Object.<anonymous> (node_modules/react-dom/lib/ReactDOMFiber.js:22:31)
at Object.<anonymous> (node_modules/react-dom/index.js:3:18) Using this simple code: import React from 'react';
import { shallow } from 'enzyme'; Note that it's react native component, note sure why addEventListener is used/required somehow. It seems just importing enzyme create the issue. |
The issue is react-native requiring an alpha version of react. This is a mistake, and the issue should be filed with them. Either react 16 should be released, or it shouldn't be solely depended upon by libs (libs working with both 15 and 16 are fine, ofc)/ |
Relevant info (I hope) for late/newcomers: facebook/react-native#13469 (comment) facebook/react-native#13291 (comment) RN has said they’re sticking with the alpha through ~0.45/0.46, and Enzyme (as above), won’t support an alpha version. So, in the absence of a change in policy on either side, expect that for at least the next few versions of RN, the incompatibility with this package will remain. At least until React 16 drops (or a RC, obviously). The RN CLI currently gives you 0.44 (and therefore the alpha by default) so be aware if you love Enzyme... and try to use it straight off a newly rolled RN project, 2.8.2 and 0.44 are going to yell at you. But I don't like getting yelled at. I want Enzyme and React Native to play nice right now!? Ok, if you still want to run this package’s current version (2.8.2) with a RN project, you can downgrade (maybe? sorry if you’re stuck at 0.43+ somehow already, friend) your RN version to 0.42. Then, just fix the accompanying dependencies/peers etc. It should look like something similar to this: "dependencies": {
"enzyme": "^2.8.2",
"prop-types": "^15.5.10",
"react": "15.4.1",
"react-native": "0.42.0"
},
"devDependencies": {
"react-dom": "^15.5.4",
"react-test-renderer": "^15.5.4",
"babel-jest": "20.0.1",
"babel-preset-react-native": "1.9.1",
"jest": "20.0.1",
"standard": "^10.0.2"
} Hopefully this helps anyone with questions about using enzyme with RN 0.44 (nope, get 0.42) and also allows this package’s maintainers to move on from this issue as there has already been a decision on their end. Cheers! |
Thanks @jlhall for the suggestion. Including the versions that you mentioned gets rid of the warnings. I wanted to try something else out so I ended up doing the following
As you can see My question is, is there any issues with this setup that i'm not immediately seeing?. As in would you not recommend using this setup until enzyme officially supports latest RN and React? |
For something to be "recommended" it usually has to have official support. If enzyme collaborators were aware of why this setup was either bad or good, then it'd be trivial for us to support it officially :-) The issue is that we don't know - you're treading on uncharted territory. |
@ljharb, Understood. Thanks for your quick comment. |
Hmm, does 2.8.2 work with react 16? I'm getting "Cannot read property 'getPublicInstance' of undefined" |
@tomitrescak no, 16 doesn't exist, only 16 alpha. We don't support alphas. |
Ok, I thought so, just got confused with the comment above claiming that 2.8.2 worked fine. Rolling bask to 15.4.3 ;) |
A couple months ago, I selected a downgraded React Native in order to use Enzyme during development. However, I've hit a point where React Native is far enough ahead that I'm running into issues not being able to use various React Native libraries with an outdated React Native version. I think it's pretty clear that the way the Facebook team has decided to version React Native and React 16 alphas is pretty non-standard, and issues have been filed with React Native on that subject. @ljharb I understand the position of not supporting alphas, but surely Enzyme should work towards supporting React 16 in anticipation of its release? Is any work being done on that currently? |
@ljharb Thanks! |
@ljharb @TiraO The fix-enzyme-for-react-16.fix file:
The package.json line:
I know. It's ugly. But it's also temporary. And it seems to work... |
@ayleesedai i'd really prefer we not have something like that on the repo, since it's an incredibly bad idea to modify things inside node_modules. Separately, that's definitely not sufficient to make everything work in React 16 - you'll get a number of surprising subtle bugs. |
@ljharb you definitively convinced me. Actually I always thought it was a bad idea, but sometimes the evil developer inside me awakes and makes me think of horrible things. Shame on me. |
react 16 beta was released, is there a plan to support it soon? the claim was that alpha versions are not supported by default, but but version do |
Refering to this comment, it will possibly be enabled by #1007. |
Please do not recommend people try out enzyme v3 from git before it's ready; please instead be patient. |
Sorry @ljharb! Check |
Temporary solution that works for me add to
Change imports of enzyme across specs into:
my versions of packages:
|
The following worked for me. In my
Then in my import { ShallowWrapper } from 'enzyme'
ShallowWrapper.prototype.instance = function() {
if (this.root !== this) {
throw new Error('ShallowWrapper::instance() can only be called on the root')
}
return this.renderer._instance ? this.renderer._instance : null
} (The only difference from the |
There's other differences; it's best to stick with react 15 until enzyme v3 comes out. |
react is now RC 2 FYI |
Great! It's now precisely zero closer to actually being a thing :-) Either it's released, or it's not. Candidates don't count, whether they're rc 2 or rc 473. Enzyme v3 is coming soon, and with it, react 16 support. Be patient. |
Sorry I was just posting that because of this reply you had made earlier.
|
Ha, touché :-) Once enzyme v3 comes out, we'll be able to easily support future RCs, and even alphas and betas. At this point, v2 is never going to support anything past v15. Soon! |
@ljharb I would like to help with getting enzyme@3 out, but I cannot seem to find any milestone ticket that notes what needs to be done. : ) |
There's a label called "v3 blockers" |
v3.0.0 is now released. |
there's a typo in the docs |
Anyone facing |
@Fatxx I've been getting that a lot recently... As a temporary workaround you can put Seems to have been fixed in newer version of react-native |
Does any minor version v2 of Enzyme support React 16? I'm upgrading and don't want to do enzyme v3 yet. |
@nbkhope no; enzyme v2 will never support react 16. Migrate to enzyme 3 first; and then upgrade to React 16. |
Hi @ljharb Does enzyme v3 supports beta version of React 16?
|
@B4bharat yes, the React 16 adapter should work with that; however, to get it properly working, someone would have to build a react-native adapter. |
React is currently in v
16.0.0-alpha.12
, but is it already planned to support it by enzyme? My specific issue currently is #875.Is it too early to implement it, as it is in alpha?
The text was updated successfully, but these errors were encountered: