-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Coverage flag breaks snapshot test #1740
Comments
I've also noticed tests that pass consistently without |
Degugging:
First line will show function name, second will show function source code. I think this issue comes from istanbul, I can investigate it tomorrow |
Yes, this is istanbul. Related issue: gotwarlost/istanbul#699 For now, I wanted to point out a hotfix for that. Just wrap your named func into anonymous proxy func: @@ -44,7 +44,7 @@ const PieChart = ({
return (
<RCTPieChart
chartRotation={chartRotationInRadians}
- onSelect={onSelectHandler}
+ onSelect={(...args) => onSelectHandler(...args)}
segments={processedSegments} And snapshot transforms then to this: @@ -2,7 +2,7 @@ exports[`PieChart Android should render pie chart 1`] = `
<RCTPieChart
chartRotation={-0.2617993877991494}
innerCircleRadius={0.55}
- onSelect={[Function onSelectHandler]}
+ onSelect={[Function onSelect]}
segments={
Array [
Object { However, this is a hack... |
yeah.. it seems like there's nothing we can do on the jest side, unless we omit function names in snapshots. |
@DmitriiAbramov Take a look on my snippets above... Recap. Given this handler (AFAIK it should be an anonymous function):
It writes this handler in snapshot:
How can it be? |
Yeah we should probably just get rid of function names in the snapshots. I originally liked this a lot but it is causing more trouble than it is worth. |
Will be fixed in 16. |
Hmmm... doesn't solve the problem completely if for some reason you're snapshotting a React element. It's name will turn |
+1 @guigrpa |
In my case I'm using enzyme to snapshot a functional stateless component in React, and I get a failed snapshot assertion with coverage enabled, but it's not - <ListItem
+ <Component
active={false}
item={
Object {
"id": "thing",
"name": "stuff",
}
}
onClick={[Function]} /> I'd be happy to isolate a repro case for this setup if it helps at all. The curious part here is that all my other snapshots are fine, it's just this instance of snapshotting a functional stateless component that has this differing output. |
@dotfold if you can isolate the test case, please file a new issue with it. |
If it helps, I get the |
@thymikee I'm working on this at the moment https://github.com/springload/mocha-chai-to-jest If you checkout the repo, set it up and run I quickly tried to use a statefull component like Let me know if this helps. |
For stateless components you need to define |
@thymikee Cool it fixed my problem. I'm just wondering how come the "normal" jest testing finds the name properly and why the coverage doesn't? Also using |
|
Node 6 infers function names. Example:
this wasn't possible in previous versions of node. It works fine when you aren't using coverage but when you do, here is what istanbul does to your code:
because of how the expression is defined, node cannot infer the name properly. The only way to fix it is in istanbul itself or by using a babel transform that changes |
Exactly! I've recently encountered this issue and I tried to fix it on the istanbul side. I forked istanbuljs/babel-plugin-istanbul#125 Could you folks let me know what you think about my proposal? |
Per istanbuljs/babel-plugin-istanbul#125 (comment) this is now fixed in |
@CGamesPlay you can use |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I think it's because of code instrumentation
Running with
jest
is just OK.Source code and func name for onSelectHandler:
jest
:And for
jest --coverage
:How I can avoid this issue? Force use anonymous functions on every place? 😯
The text was updated successfully, but these errors were encountered: