/
jest-image-snapshot-tests.ts
60 lines (49 loc) · 1.77 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
// Typescript Version: 2.3
import { configureToMatchImageSnapshot, MatchImageSnapshotOptions, toMatchImageSnapshot } from 'jest-image-snapshot';
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',
diffDirection: 'vertical',
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);
});