Skip to content

Commit 4b10ed2

Browse files
Kent C. Doddsthymikee
authored andcommitted
Allow for setting the annotation for strings (#15)
1 parent 14b6aeb commit 4b10ed2

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ expect(valueA: any).toMatchDiffSnapshot(valueB: any, options?: Options) => void
135135
* `expand: boolean` (default: `false`) – expand the diff, so the whole information is preserved
136136
* `colors: boolean` (default: `false`) – preserve color information from Jest diff
137137
* `contextLines: number` (default: 5) - number of context lines to be shown at the beginning and at the end of a snapshot
138+
* `aAnnotation: string` (default: `'First Value'`) - the annotation indicating from which serialization the `-` lines are
139+
* `bAnnotation: string` (default: `'Second Value'`) - the annotation indicating from which serialization the `+` lines are
140+
138141

139142
---
140143

__tests__/getSnapshotDiffSerializer.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22

33
const snapshotDiff = require('../src/index');
4-
4+
// $FlowFixMe – wrong type declaration in flow-typed/[email protected]
55
expect.addSnapshotSerializer(snapshotDiff.getSnapshotDiffSerializer());
66

77
test('serialize text diff output', () => {

src/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ type Options = {
1313
expand?: boolean,
1414
colors?: boolean,
1515
contextLines?: number,
16+
aAnnotation?: string,
17+
bAnnotation?: string,
1618
};
1719

1820
const defaultOptions = {
1921
expand: false,
2022
colors: false,
2123
contextLines: -1, // Forces to use default from Jest
24+
aAnnotation: 'First value',
25+
bAnnotation: 'Second value',
2226
};
2327

2428
const SNAPSHOT_TITLE = 'Snapshot Diff:\n';
@@ -49,8 +53,8 @@ function diffStrings(valueA: any, valueB: any, options: Options) {
4953
return diff(valueA, valueB, {
5054
expand: options.expand,
5155
contextLines: options.contextLines,
52-
aAnnotation: 'First value',
53-
bAnnotation: 'Second value',
56+
aAnnotation: options.aAnnotation,
57+
bAnnotation: options.bAnnotation,
5458
});
5559
}
5660

0 commit comments

Comments
 (0)