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

Created on 5 Jul 2018  ·  11Comments  ·  Source: facebook/jest

🐛 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

Enhancement Help Wanted

Most helpful comment

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")

All 11 comments

cc @azz

Mind setting up a reproduction?

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

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

@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.

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")

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?)

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 ^^

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

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

Was this page helpful?
0 / 5 - 0 ratings