Skip to content

Error in snapshotSerializer test doesn't have useful stack trace #3302

@Daniel15

Description

@Daniel15

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
If a snapshot serializer's test method throws an exception, the stack trace doesn't point to it at all. This can make it difficult to determine where the exception is coming from.

Example:
Serializer:

const DummySerializer = {
  test: val => { throw new Error('Where is this error?') },
  print: val => '',
};

Config:

{
  "snapshotSerializers": [
    "<rootDir>/dummySerializer.js"
  ],
  "testRegex": ".*-test\\.js$"
}

Test:

test('hello world', () => {
  expect('foo').toMatchSnapshot();
})

Output:

 FAIL  ./add-test.js
  ● hello world

    Where is this error?
      
      at Object.<anonymous>.test (add-test.js:2:17)

add-test.js:2 is simply the expect('foo').toMatchSnapshot() call.

repl.it demo: https://repl.it/HKH4

What is the expected behavior?
Stack trace should point to the test method in the snapshot serializer.

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
I encountered this internally at Facebook, but can also repro on Jest v19.0.2 using repl.it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions