Skip to content
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

Inline Snapshot Error could use clarification? "Multiple inline snapshots for the same call are not supported." #6636

Closed
wldcordeiro opened this issue Jul 5, 2018 · 14 comments

Comments

@wldcordeiro
Copy link

🐛 Bug Report

I updated to Jest 23.3 and wanted to give the new inline snapshots a try and had failures that I struggling to understand. I received the error above and this stacktrace, but it doesn't point me at all at my code so I don't know where or what I should fix.

 ● Test suite failed to run

    Jest: Multiple inline snapshots for the same call are not supported.

      at CallExpression (node_modules/jest-snapshot/build/inline_snapshots.js:165:15)
      at NodePath._call (node_modules/babel-traverse/lib/path/context.js:76:18)
      at NodePath.call (node_modules/babel-traverse/lib/path/context.js:48:17)
      at NodePath.visit (node_modules/babel-traverse/lib/path/context.js:105:12)
      at TraversalContext.visitQueue (node_modules/babel-traverse/lib/context.js:150:16)
      at TraversalContext.visitSingle (node_modules/babel-traverse/lib/context.js:108:19)
      at TraversalContext.visit (node_modules/babel-traverse/lib/context.js:192:19)
      at Function.Object.<anonymous>.traverse.node (node_modules/babel-traverse/lib/index.js:114:17)
      at NodePath.visit (node_modules/babel-traverse/lib/path/context.js:115:19)
      at TraversalContext.visitQueue (node_modules/babel-traverse/lib/context.js:150:16)
      at TraversalContext.visitMultiple (node_modules/babel-traverse/lib/context.js:103:17)
      at TraversalContext.visit (node_modules/babel-traverse/lib/context.js:190:19)
      at Function.Object.<anonymous>.traverse.node (node_modules/babel-traverse/lib/index.js:114:17)
      at NodePath.visit (node_modules/babel-traverse/lib/path/context.js:115:19)
      at TraversalContext.visitQueue (node_modules/babel-traverse/lib/context.js:150:16)
      at TraversalContext.visitSingle (node_modules/babel-traverse/lib/context.js:108:19)
      at TraversalContext.visit (node_modules/babel-traverse/lib/context.js:192:19)
      at Function.Object.<anonymous>.traverse.node (node_modules/babel-traverse/lib/index.js:114:17)
      at NodePath.visit (node_modules/babel-traverse/lib/path/context.js:115:19)
      at TraversalContext.visitQueue (node_modules/babel-traverse/lib/context.js:150:16)
      at TraversalContext.visitMultiple (node_modules/babel-traverse/lib/context.js:103:17)
      at TraversalContext.visit (node_modules/babel-traverse/lib/context.js:190:19)
      at Function.Object.<anonymous>.traverse.node (node_modules/babel-traverse/lib/index.js:114:17)
      at NodePath.visit (node_modules/babel-traverse/lib/path/context.js:115:19)
      at TraversalContext.visitQueue (node_modules/babel-traverse/lib/context.js:150:16)
      at TraversalContext.visitSingle (node_modules/babel-traverse/lib/context.js:108:19)
      at TraversalContext.visit (node_modules/babel-traverse/lib/context.js:192:19)
      at Function.Object.<anonymous>.traverse.node (node_modules/babel-traverse/lib/index.js:114:17)
      at NodePath.visit (node_modules/babel-traverse/lib/path/context.js:115:19)
      at TraversalContext.visitQueue (node_modules/babel-traverse/lib/context.js:150:16)
      at TraversalContext.visitMultiple (node_modules/babel-traverse/lib/context.js:103:17)
      at TraversalContext.visit (node_modules/babel-traverse/lib/context.js:190:19)
      at Function.Object.<anonymous>.traverse.node (node_modules/babel-traverse/lib/index.js:114:17)
      at NodePath.visit (node_modules/babel-traverse/lib/path/context.js:115:19)
      at TraversalContext.visitQueue (node_modules/babel-traverse/lib/context.js:150:16)
      at TraversalContext.visitSingle (node_modules/babel-traverse/lib/context.js:108:19)
      at TraversalContext.visit (node_modules/babel-traverse/lib/context.js:192:19)
      at Function.Object.<anonymous>.traverse.node (node_modules/babel-traverse/lib/index.js:114:17)
      at NodePath.visit (node_modules/babel-traverse/lib/path/context.js:115:19)
      at TraversalContext.visitQueue (node_modules/babel-traverse/lib/context.js:150:16)
      at TraversalContext.visitSingle (node_modules/babel-traverse/lib/context.js:108:19)
      at TraversalContext.visit (node_modules/babel-traverse/lib/context.js:192:19)
      at Function.Object.<anonymous>.traverse.node (node_modules/babel-traverse/lib/index.js:114:17)
      at NodePath.visit (node_modules/babel-traverse/lib/path/context.js:115:19)
      at TraversalContext.visitQueue (node_modules/babel-traverse/lib/context.js:150:16)
      at TraversalContext.visitMultiple (node_modules/babel-traverse/lib/context.js:103:17)
      at TraversalContext.visit (node_modules/babel-traverse/lib/context.js:190:19)
      at Function.Object.<anonymous>.traverse.node (node_modules/babel-traverse/lib/index.js:114:17)
      at NodePath.visit (node_modules/babel-traverse/lib/path/context.js:115:19)
      at TraversalContext.visitQueue (node_modules/babel-traverse/lib/context.js:150:16)
      at TraversalContext.visitSingle (node_modules/babel-traverse/lib/context.js:108:19)
      at TraversalContext.visit (node_modules/babel-traverse/lib/context.js:192:19)
      at Function.Object.<anonymous>.traverse.node (node_modules/babel-traverse/lib/index.js:114:17)
      at traverse (node_modules/babel-traverse/lib/index.js:79:12)
      at Object.parse$2 [as parse] (node_modules/prettier/index.js:7000:19)
      at coreFormat (node_modules/prettier/index.js:10196:23)
      at format (node_modules/prettier/index.js:10367:16)
      at formatWithCursor (node_modules/prettier/index.js:10379:12)
      at node_modules/prettier/index.js:31222:15
      at Object.format (node_modules/prettier/index.js:31241:12)

To Reproduce

Steps to reproduce the behavior:

I'm not sure? I had a custom snapshot serializer and a test where I changed .toMatchSnapshot to .toMatchInlineSnapshot and the error is too cryptic so far.

Expected behavior

That the error and stacktrace would be more informative as to what needs to be changed.

Link to repl or repo (highly encouraged)

Please provide either a repl.it demo or a minimal repository on GitHub.

Issues without a reproduction link are likely to stall.

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS High Sierra 10.13.1
    CPU: x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
  Binaries:
    Node: 9.11.1 - ~/.nvm/versions/node/v9.11.1/bin/node
    Yarn: 1.7.0 - ~/.yarn/bin/yarn
    npm: 5.7.0 - ~/.nvm/versions/node/v9.11.1/bin/npm
@thymikee
Copy link
Collaborator

thymikee commented Jul 5, 2018

cc @azz

@SimenB
Copy link
Member

SimenB commented Jul 6, 2018

Mind setting up a reproduction?

@azz
Copy link
Contributor

azz commented Jul 6, 2018

Was the toMatchInlineSnapshot inside a loop or otherwise called multiple times?

@SimenB
Copy link
Member

SimenB commented Jul 6, 2018

Would be nice either way to throw an error with the async error stack so it'd point back to the invocation

@wldcordeiro
Copy link
Author

@azz I figured it out. :) I had these in places where in-lining wasn't possible (separate helper function call) but from the looks of it I can convert my helper/serializer into a custom .toMatchXInlineSnapshot() and this shouldn't be a problem.

@SimenB
Copy link
Member

SimenB commented Jul 9, 2018

OK, so not a bug, then. Good! 🙂 But I still think we should fix the trace, plus maybe add some hints to the error message (like, "do not use in loops or in helper function")

@wldcordeiro
Copy link
Author

Agreed @SimenB the trace would have made it really apparent to me along with the hint. It would be neat to see some way to inline for a test.each but the looping nature may just make it impossible (maybe a "results table" that prettier inserts after your table?)

@despairblue
Copy link

This also happens in conjunction with jest.retryTimes. So with circus as a test runner the following code will yield the same error:

jest.retryTimes(1)

describe('add', () => {
  it('should add two numbers', () => {
    expect(1 + 1).toMatchInlineSnapshot()
    expect(1 + 1).toBe(3);
  });
});

Took me a while to figure that out ^^

@SimenB
Copy link
Member

SimenB commented Jul 31, 2019

That seems like a bug. Might've been fixed by #8629?

@despairblue
Copy link

That's possible, is there a prerelease I could try?

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the Stale label Feb 25, 2022
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants