Handle function name inference
See original GitHub issueThe best way to explain things is via a repo: https://github.com/kentcdodds/issue-babel-plugin-istanbul-fn-name
Here’s a copy/paste of the README:
issue-babel-plugin-istanbul-fn-name
This demonstrates that due to how babel-plugin-istanbul wraps functions, the name of the function is lost
This is a bug and should be fixed.
Why?
This is causing issues with Jest snapshot testing of React components
Reproduce:
See the npm scripts, or just run things manually:
node test.js
Everything passes fine
babel-node --plugins istanbul test.js
You get two failures. One for the Foobar
function:
const Foobar = function() {}
And the other for the Bar
function:
const Bar = () => {}
The istanbul-transformed (babel --plugins istanbul index.js
) version of these functions looks like this:
const Bar = (++cov_1788vtfzzh.s[0], () => {
++cov_1788vtfzzh.f[1];
});
const Foobar = (++cov_1788vtfzzh.s[2], function () {
++cov_1788vtfzzh.f[3];
});
This makes it so the JS engine can’t do function name inference which causes the issue.
I’m not sure what the babel plugin can do about arrow functions… Can’t really give those a name. Definitely possible, but you’d have to do some fancy work to make things work.
But for the function expression that’s simple enough.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:8
- Comments:10 (7 by maintainers)
Top GitHub Comments
Poof!
@kentcdodds could I convince you to try out:
npm cache clear; npm i babel-plugin-istanbul@next
? I believe it has some new logic for handling inferred function names which should solve this issue.