-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathjest.setup.ts
More file actions
80 lines (75 loc) · 2.52 KB
/
jest.setup.ts
File metadata and controls
80 lines (75 loc) · 2.52 KB
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
77
78
79
80
import { TextEncoder, TextDecoder } from 'util';
// Polyfill TextEncoder and TextDecoder for jsom.
Object.assign(global, { TextDecoder, TextEncoder });
// Mock svg functions that jsdom does not implement.
Object.defineProperty(global.SVGSVGElement.prototype, 'createSVGMatrix', {
writable: true,
value: jest.fn().mockImplementation(() => ({
martix: jest.fn(() => [[]]),
a: 0,
b: 0,
c: 0,
d: 0,
e: 0,
f: 0,
flipX: jest.fn().mockImplementation(() => global.SVGSVGElement),
flipY: jest.fn().mockImplementation(() => global.SVGSVGElement),
inverse: jest.fn().mockImplementation(() => global.SVGSVGElement),
multiply: jest.fn().mockImplementation(() => global.SVGSVGElement),
rotate: jest.fn().mockImplementation(() => ({
translate: jest.fn().mockImplementation(() => ({
rotate: jest.fn(),
})),
})),
rotateFromVector: jest.fn().mockImplementation(
() => global.SVGSVGElement
),
scale: jest.fn().mockImplementation(() => global.SVGSVGElement),
scaleNonUniform: jest.fn().mockImplementation(
() => global.SVGSVGElement
),
skewX: jest.fn().mockImplementation(() => global.SVGSVGElement),
skewY: jest.fn().mockImplementation(() => global.SVGSVGElement),
translate: jest.fn().mockImplementation(() => ({
multiply: jest.fn().mockImplementation(() => ({
multiply: jest.fn().mockImplementation(
() => global.SVGSVGElement
),
})),
})),
})),
});
Object.defineProperty(global.SVGSVGElement.prototype, 'createSVGPoint', {
writable: true,
value: jest.fn().mockImplementation(() => ({
x: 0,
y: 0,
matrixTransform: jest.fn().mockImplementation(() => ({
x: 0,
y: 0,
})),
})),
});
Object.defineProperty(global.SVGSVGElement.prototype, 'createSVGTransform', {
writable: true,
value: jest.fn().mockImplementation(() => ({
angle: 0,
matrix: {
a: 1,
b: 0,
c: 0,
d: 1,
e: 0,
f: 0,
multiply: jest.fn(),
},
setMatrix: jest.fn(),
setTranslate: jest.fn(),
})),
});
// Mock the ResizeObserver API, which is not implemented in jsdom.
global.ResizeObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
}));