Skip to content

Commit aadfb75

Browse files
jlongsterKent C. Dodds
authored andcommitted
docs: add note about snapshot diffing (#55)
1 parent e38ce02 commit aadfb75

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,27 @@ react components.
687687

688688
</details>
689689

690+
<details>
691+
692+
<summary>Why isn't snapshot diffing working?</summary>
693+
694+
If you use the
695+
[snapshot-diff](https://github.com/jest-community/snapshot-diff)
696+
library to save snapshot diffs, it won't work out of the box because
697+
this library uses the DOM which is mutable. Changes don't return new
698+
objects so snapshot-diff will think it's the same object and avoid diffing it.
699+
700+
Luckily there's an easy to way to make it work: clone the DOM when
701+
passing it into snapshot-diff. It looks like this:
702+
703+
```js
704+
const firstVersion = container.cloneNode(true);
705+
// Do some changes
706+
snapshotDiff(firstVersion, container.cloneNode(true));
707+
```
708+
709+
</details>
710+
690711
## Other Solutions
691712

692713
In preparing this project,

0 commit comments

Comments
 (0)