-
Notifications
You must be signed in to change notification settings - Fork 135
/
forEach.spec.ts
26 lines (23 loc) · 965 Bytes
/
forEach.spec.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
import type { BuildEnvWindow } from './buildEnv'
import { startLeakDetection, stopLeakDetection } from './leakDetection'
beforeEach(() => {
;(window as unknown as BuildEnvWindow).__BUILD_ENV__SDK_VERSION__ = 'test'
// reset globals
;(window as any).DD_LOGS = {}
;(window as any).DD_RUM = {}
// prevent 'Some of your tests did a full page reload!' issue
window.onbeforeunload = () => 'stop'
startLeakDetection()
// Note: clearing cookies should be done in `beforeEach` rather than `afterEach`, because in some
// cases the test patches the `document.cookie` getter (ex: `spyOnProperty(document, 'cookie',
// 'get')`), which would prevent the `clearAllCookies` function from working properly.
clearAllCookies()
})
afterEach(() => {
stopLeakDetection()
})
function clearAllCookies() {
document.cookie.split(';').forEach((c) => {
document.cookie = c.replace(/=.*/, `=;expires=${new Date().toUTCString()};path=/;samesite=strict`)
})
}