question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

jest-emotion and snapshot-diff not playing nice

See original GitHub issue

Current behavior:

jest-emotion doesn’t appear to work as a serializer for snapshot-diff. Tried various permutations of the config and the test setup but it doesn’t play nice. It’s unclear if this is a problem with the docs or an API thing.

To reproduce:

Minimal repo: https://github.com/DarkPurple141/jest-emotion-typescript-minimal/tree/master

  1. install dependencies and run jest

Expected behavior:

Environment information:

  • react version: 16.9
  • emotion version: 10.0.28

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Andaristcommented, Jun 11, 2020

I’ve looked very quickly and some of my findings are:

  • snapshot-diff is not using by default builtin serializers, it only uses a wrapper around react serializer which is based on React elements, react-test-renderer, etc. So it doesn’t work with JSDOM output
  • it also only works with old serializer API - the one using { test, print } interface when the new API is using { test, serialize }, this makes it impossible to reuse all current jest’s builtin serializers because they are written using the new API.
1reaction
Andaristcommented, Jun 11, 2020

Ok, I’ve managed to see what’s your issue but it wasn’t at all apparent where I should look for it as you have provided 3 different test files without pointing to a specific problem. app.test.tsx gave me an answer but this was the last place I was looking into.

It seems that toMatchDiffSnapshot just doesn’t run through added custom serializers: https://github.com/jest-community/snapshot-diff/blob/2d81e0a5ca04f682cebf13cf94c9dd369d4c81c7/src/index.js#L89 https://github.com/jest-community/snapshot-diff/blob/2d81e0a5ca04f682cebf13cf94c9dd369d4c81c7/src/index.js#L37 but it seems that you maybe can tell it to run through by using setSerializers: https://github.com/jest-community/snapshot-diff/blob/2d81e0a5ca04f682cebf13cf94c9dd369d4c81c7/src/index.js#L113

I hope this answers your question, if not - feel free to comment back but I’m going to close this right now as I think it got answered.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest Suite Doesn't Output Color For The Snapshot Diff
When we run our test, Jest automatically generates a snapshot of the rendered component and puts it inside the __tests__ directory. If we...
Read more >
The snapshot-diff from jest-community - GithubHelp
Jest mock names not honoured in resulting snapshot. I've encountered an issue where taking a snapshot diff doesn't maintain a mock functions name....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found