Skip to content

Commit 992a35c

Browse files
authored
fix: add setSerializers and defaultSerializers to TS types (#95)
1 parent a2a5c16 commit 992a35c

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

index.d.ts

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,60 @@
11
/// <reference types="jest"/>
22

33
type DiffOptions = {
4-
expand?: boolean
5-
colors?: boolean
6-
contextLines?: number
7-
stablePatchmarks?: boolean
8-
aAnnotation?: string
9-
bAnnotation?: string
10-
}
4+
expand?: boolean;
5+
colors?: boolean;
6+
contextLines?: number;
7+
stablePatchmarks?: boolean;
8+
aAnnotation?: string;
9+
bAnnotation?: string;
10+
};
1111

1212
declare namespace jest {
1313
interface Matchers<R, T> {
1414
/**
1515
* Compare the difference between the actual in the `expect()`
1616
* vs the object inside `valueB` with some extra options.
1717
*/
18-
toMatchDiffSnapshot(valueB: any, options?: DiffOptions, testName?: string): R
18+
toMatchDiffSnapshot(
19+
valueB: any,
20+
options?: DiffOptions,
21+
testName?: string
22+
): R;
1923
}
2024
}
2125

22-
declare module "snapshot-diff" {
26+
interface Serializer {
27+
test: (value: any) => boolean;
28+
print: (value: any, _serializer?: Function) => string;
29+
diffOptions: (valueA: any, valueB: any) => DiffOptions;
30+
}
31+
32+
declare module 'snapshot-diff' {
2333
interface SnapshotDiff {
2434
/**
2535
* Compare the changes from a, to b
2636
*/
27-
(a: any, b: any, options?: DiffOptions): string
37+
(a: any, b: any, options?: DiffOptions): string;
2838
/**
2939
* Allows you to pull out toMatchDiffSnapshot and
3040
* make it available via `expect.extend({ toMatchDiffSnapshot })`.
3141
*/
32-
toMatchDiffSnapshot: jest.CustomMatcher
42+
toMatchDiffSnapshot: jest.CustomMatcher;
3343
/**
3444
* By default Jest adds extra quotes around strings so it makes diff
3545
* snapshots of objects too noisy. To fix this – snapshot-diff comes
3646
* with custom serializer.
3747
*/
38-
getSnapshotDiffSerializer: () => jest.SnapshotSerializerPlugin
48+
getSnapshotDiffSerializer: () => jest.SnapshotSerializerPlugin;
49+
/**
50+
* Add new serializers for unsupported data types, or to set a different
51+
* serializer for React components. If you want to keep the default React
52+
* serializer in place, don't forget to add the default serializers to your
53+
* list of serializers.
54+
*/
55+
setSerializers: (serializers: Array<Serializer>) => void;
56+
defaultSerializers: Array<Serializer>;
3957
}
40-
const diff: SnapshotDiff
41-
export = diff
58+
const diff: SnapshotDiff;
59+
export = diff;
4260
}

0 commit comments

Comments
 (0)