Skip to content

Commit 4f7e4ad

Browse files
Add docs about toMatchDiffSnapshot matcher.
1 parent 58ae918 commit 4f7e4ad

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,37 @@ yarn add --dev snapshot-diff
1212
## Usage
1313

1414
```js
15-
const snapshotDiff = require('snapshot-diff');
15+
const { snapshotDiff, toMatchDiffSnapshot } = require('snapshot-diff');
16+
17+
// register custom matcher (optional)
18+
expect.extend({ toMatchDiffSnapshot });
1619

1720
test('snapshot difference between 2 strings', () => {
21+
// use default jest snapshot matcher
1822
expect(snapshotDiff(a, b)).toMatchSnapshot();
23+
24+
// or use custom diff snapshot matcher
25+
expect(a).toMatchDiffSnapshot(b);
1926
});
2027

2128
const React = require('react');
2229
const Component = require('./Component');
2330

2431
test('snapshot difference between 2 React components state', () => {
32+
// use default jest matcher
2533
expect(
2634
snapshotDiff(
2735
<Component test="say" />,
2836
<Component test="my name" />
2937
)
3038
).toMatchSnapshot();
39+
40+
// or use custom diff snapshot matcher
41+
expect(
42+
<Component test="say" />
43+
).toMatchDiffSnapshot(
44+
<Component test="my name" />
45+
);
3146
});
3247
```
3348

0 commit comments

Comments
 (0)