From 70c9774a5d4c2e7f586dc876cb3d83bf94310320 Mon Sep 17 00:00:00 2001 From: James Long Date: Fri, 13 Apr 2018 14:33:42 -0400 Subject: [PATCH] Add note about snapshot diffing --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 297ce6f6..46c31ab0 100644 --- a/README.md +++ b/README.md @@ -687,6 +687,27 @@ react components. +
+ +Why isn't snapshot diffing working? + +If you use the +[snapshot-diff](https://github.com/jest-community/snapshot-diff) +library to save snapshot diffs, it won't work out of the box because +this library uses the DOM which is mutable. Changes don't return new +objects so snapshot-diff will think it's the same object and avoid diffing it. + +Luckily there's an easy to way to make it work: clone the DOM when +passing it into snapshot-diff. It looks like this: + +```js +const firstVersion = container.cloneNode(true); +// Do some changes +snapshotDiff(firstVersion, container.cloneNode(true)); +``` + +
+ ## Other Solutions In preparing this project,