This week was full of news! We saw the long awaited React 16 release:
With great free content around new features:
We also had the new version of Enzyme fixing a lot of annoying bugs:
I already saw it in Twitter, so what?
Hold my 🍺 dear reader. These releases have one important thing in common:
They are not inflicting pain on ecosystem and library maintainers.
At least, not in the minor version! 🎉, if you’ve been here for a while, maybe you remember last time, we had some issues:
But, NOT THIS TIME!!1
It is a marvellous work, congratulations everybody involved!
It's time to update your configuration, without much pain!
I've prepared 2 examples:
- React 15.6.2, Enzyme 3.0.0 and Jest 21.2.1
- React 16.0.0, Enzyme 3.0.0 and Jest 21.2.1
You don’t need to update to React 16 to use Enzyme 3 and vice-versa. Beautiful, isn’t it?
You can check the repositories here:
For React 16
enzyme-v3-and-react-16 - Example of how to setup React 16, Enzyme 3 and Jest 21
For React 15
enzyme-v3-and-react-15 - Example of how to setup React 15, Enzyme 3 and Jest 21
How about the main changes?
Glad you asked! Let's see a basic overview about the changes:
- To better support others "React-like" libraries, Preact/Inferno, we've the new concept of Adapters. They’re pluggable libraries, responsible for handle the rendering of the UI Library you’re using.
- Officially, Enzyme 3 was released with full support for React 13~16. (FYI, we already have a Preact Adapter).
- Properties like
.options, they have been removed from the
- You can disable the lifecycle globally with
disableLifecycleMethodsoption in your Enzyme configuration.
And many many more goodies! You can check the complete list in the migration guide.
- Now is required a environment with the new ES6 data structure, Set and Map. You can use
- React also depends on
requestAnimationFrame, even in test environments. In my examples, I've used the npm package
- Don't believe me? Good for me, I just
git cherry-pickwords from this Gist created by Dan 2 months ago.
If you’re still in doubt, I recommend you to check the repositories!
There's almost zero pain migrating to Enzyme 3, "..Airbnb has one of the largest enzyme test suites, coming in at around 30,000 enzyme unit tests. After upgrading enzyme to v3.x in Airbnb’s code base, 99.6% of these tests succeeded.." (from the migration guide).
React 16 introduces a bit of friction, but is worth it!
Already using these new versions? Share with us in the comment! Would be awesome to hear from you, dear reader!
That's all folks, thanks for your time, and see you in the next major version! 👋