Babel 7.4 + core-js 3 causing tons of padded zeros in Jest tests
See original GitHub issueBug Report
Current Behavior
I’m in the process of upgrading an internal project to Babel 7.4 (from 7.2) and core-js 3 (from 2). The Webpack bundle works fine, however, a ton of Jest tests are failing with unexpected values being padded with a ton of zeros. Some examples:
<Rating /> › renders the star rating
expect(received).toBe(expected) // Object.is equality
Expected: "12"
Received: "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
<Row /> › renders data
expect(received).toBe(expected) // Object.is equality
Expected: "7"
Received: "0000000000000000000000000000000000000000000000000000000000000000"
<BottomBar /> › renders the correct content for end steps
expect(value).toMatchSnapshot()
Received value does not match stored snapshot "<BottomBar /> renders the correct content for end steps 1".
- Snapshot
+ Received
@@ -5,13 +5,43 @@
className="primary_4ommi7"
>
<Text
muted={true}
>
- 5
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
/
- 5
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
</Text>
</div>
<div
className="after_m2rwu8"
>
I’ve tried all the following combinations. Seems anything using core-js v3 is broken.
- Babel 7.4 + core-js 2 - WORKS
- Babel 7.4 + core-js 2 + “usage” built-in - WORKS (but logs warnings)
- Babel 7.4 + core-js 3 + “usage” built-in - FAILS with padded zeros
- Babel 7.4 + core-js 3 + “entry” built-in - FAILS with padded zeros
Input Code
Internal only but it’s just basic React components.
Expected behavior/code
It simply works with core-js 3.
Babel Configuration (.babelrc, package.json, cli command)
const isTesting = process.env.NODE_ENV === 'test';
module.exports = {
presets: [
[
'@babel/preset-env',
{
// corejs: 3,
// useBuiltIns: 'usage',
loose: true,
shippedProposals: true,
targets: isTesting ? { node: 'current' } : { browsers: ['last 3 Chrome versions'] },
modules: isTesting ? 'commonjs' : false,
},
],
'@babel/preset-react',
'@babel/preset-typescript',
],
plugins: [
'babel-plugin-graphql-tag',
// TS doesn't support optional chaining, so we use idx instead
'babel-plugin-idx',
'@babel/plugin-proposal-class-properties',
[
'@babel/transform-runtime',
{
// corejs: 3,
helpers: true,
regenerator: false,
useESModules: !isTesting,
},
],
'react-loadable/babel',
],
};
Environment
- Babel version(s): 7.4.3
- Node/npm version: node 10.14 / npm 6.5 / yarn 1.15
- OS: OSX 10.14
- Monorepo: no
- How you are using Babel: cli
Possible Solution
Digging into root cause. Found nothing yet.
Additional context/Screenshots
N/A
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Jest is using the wrong version of core-js when testing react ...
At runtime, everything is fine and the library works really well: pages load, components are draggable where they should be draggable, etc etc....
Read more >@babel/core | Yarn - Package Manager
Intro. Babel is a tool that helps you write code in the latest version of JavaScript. When your supported environments don't support certain...
Read more >Planning for 7.0 - Babel.js
React promotes the use of JSX, class properties (now Stage 3), object rest/spread (now Stage 3) and we all believe that it's just...
Read more >Dependencies | hlp | npm - Open Source Insights
arrow_right @babel/cli. 7.19.3 Notes Relation Licenses Dependencies 37
Version 7.19.3 Published Description
arrow_right @babel/core. 7.20.5 Notes Relation Licenses Dependencies 51
Version 7.20.5 Published Description
Read more >mozilla-release: changeset 533541 ... - Mercurial
devtools/client/aboutdebugging-new/test/jest/components/__snapshots__/shared- ... resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.4.3.tgz# ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@nicolo-ribaudo Honestly, never figured this out. I ended up deleting the lock file, updating all versions to the latest, and just migrating everything. It eventually went away, so I’ll close this.
Seems like it was a weird combo of certain dep versions.
Hi @milesj, sorry for the long delay. Would you be able to create a repository I can download to reproduce the issue? I have never used enzyme, so I don’t know where to start from.