forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest-image-snapshot-tests.ts
76 lines (63 loc) · 2.18 KB
/
jest-image-snapshot-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { expect } from 'expect';
import {
configureToMatchImageSnapshot,
MatchImageSnapshotOptions,
toMatchImageSnapshot,
updateSnapshotState,
} from 'jest-image-snapshot';
declare const it: any;
it('should be able to use toMatchImageSnapshot in a test', () => {
expect.extend({ toMatchImageSnapshot });
expect(400).toMatchImageSnapshot();
});
it('should be able to use configureToMatchImageSnapshot in a test', () => {
const matchFn = configureToMatchImageSnapshot({
allowSizeMismatch: true,
noColors: true,
customDiffConfig: {
threshold: 5,
includeAA: false,
},
failureThreshold: 10,
failureThresholdType: 'percent',
});
expect.extend({ toMatchImageSnapshot: matchFn });
expect('Me').toMatchImageSnapshot();
});
it('Should be able to use configuration directly in toMatchImageSnapshot', () => {
expect.extend({ toMatchImageSnapshot });
const options: MatchImageSnapshotOptions = {
allowSizeMismatch: false,
noColors: true,
customDiffConfig: {
threshold: 5,
includeAA: false,
},
customDiffDir: './diffs',
storeReceivedOnFailure: true,
customReceivedDir: '/usr/local/__received_output__',
diffDirection: 'vertical',
dumpInlineDiffToConsole: true,
updatePassedSnapshot: true,
failureThreshold: 10,
failureThresholdType: 'percent',
};
expect('Me').toMatchImageSnapshot(options);
});
it('Should be able to use string as customSnapshotIdentifier', () => {
const options: MatchImageSnapshotOptions = {
customSnapshotIdentifier: 'string identifier',
};
expect('Me').toMatchImageSnapshot(options);
});
it('Should be able to use callback as customSnapshotIdentifier', () => {
const options: MatchImageSnapshotOptions = {
customSnapshotIdentifier: () => 'string identifier',
};
expect('Me').toMatchImageSnapshot(options);
});
it('mutates original state', () => {
const originalState = { some: 'value' };
updateSnapshotState(originalState, { another: 'val' });
expect(originalState).toEqual({ some: 'value', another: 'val' });
});