-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathjest.setup.js
More file actions
69 lines (61 loc) · 1.72 KB
/
jest.setup.js
File metadata and controls
69 lines (61 loc) · 1.72 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
import '@testing-library/jest-dom'
import { outdent } from 'outdent'
/**
* Mock fetch() function for jsdom
*/
Object.defineProperty(window, 'fetch', {
configurable: true,
writable: true,
value: jest.fn().mockResolvedValue(undefined)
})
/**
* Mock out SVG functionality that isn't implemented by JSDOM.
* These mocks are not remotely realistic, so don't depend on them
* for testing complex SVG interactions.
*/
Object.defineProperty(globalThis.SVGElement.prototype, 'getScreenCTM', {
configurable: true,
writable: true,
value: jest.fn().mockImplementation(() => ({
a: 1,
b: 0,
c: 0,
d: 1,
e: 0,
f: 0,
inverse: jest.fn().mockReturnThis(),
multiply: jest.fn().mockReturnThis(),
translate: jest.fn().mockReturnThis(),
scale: jest.fn().mockReturnThis(),
rotate: jest.fn().mockReturnThis()
}))
})
Object.defineProperty(globalThis.SVGElement.prototype, 'createSVGPoint', {
configurable: true,
writable: true,
value: jest.fn().mockImplementation(() => ({
x: 0,
y: 0,
matrixTransform: jest.fn().mockReturnThis
}))
})
Object.defineProperty(globalThis.SVGElement.prototype, 'isPointInFill', {
configurable: true,
writable: true,
value: jest.fn().mockImplementation(() => true)
})
beforeEach(() => {
const stylesheet = document.createElement('style')
stylesheet.innerHTML = outdent`
:root {
--nhsuk-breakpoint-mobile: 20rem;
--nhsuk-breakpoint-tablet: 40.0625rem;
--nhsuk-breakpoint-desktop: 48.0625rem;
--nhsuk-breakpoint-large-desktop: 61.875rem;
}
`
// Add styles for NHS.UK frontend checks
document.head.appendChild(stylesheet)
// Flag NHS.UK frontend as supported
document.body.classList.add('nhsuk-frontend-supported')
})