snapshot-diff icon indicating copy to clipboard operation
snapshot-diff copied to clipboard

Remove unnecessary boilerplate from snapshots

Open dantman opened this issue 6 years ago • 3 comments

I'm using snapshot-diff with the custom serializer:

  "jest": {
    "snapshotSerializers": [
      "snapshot-diff/serializer.js"
    ]
}
expect(initialTemplate).toMatchDiffSnapshot(result, {contextLines: 3});

And I'm getting snapshot output like this:

exports[`Template actions setPageTitle should set the meta.title belonging to the page 1`] = `
Snapshot Diff:
- First value
+ Second value

@@ -16,7 +16,7 @@
    "pages": Object {
      "test-01": Object {
        "meta": Object {
-         "title": "Untitled",
+         "title": "Page 1",
        },
      },
      ...
`;

It's a little annoying because these lines are redundant, the test isn't going to cease to be a snapshot diff and I don't need information about how diffs work embedded inside every single snapshot.

Snapshot Diff:
- First value
+ Second value

dantman avatar Mar 17 '18 23:03 dantman

Hm, maybe we should only leave this "legend" feature for the React components or even remove at all (because it gets messy with components having more props). Indeed it doesn't provide any value, as I see it now.

If you ask me, I'm happy to accept a PR changing it and publish as a major version bump.

thymikee avatar Mar 17 '18 23:03 thymikee

cc @ferrannp @kentcdodds @jlongster

thymikee avatar Mar 17 '18 23:03 thymikee

I like the heading. I say keep it. If it's not there then folks seeing the snapshot could be confused. Especially if they break it making seemingly unrelated changes and see the output in their terminal which is quite hard to understand frankly.

kentcdodds avatar Mar 18 '18 00:03 kentcdodds