-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
jest.setup.ts
49 lines (44 loc) · 1.12 KB
/
jest.setup.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
import '@testing-library/jest-dom'
import '@testing-library/jest-dom/extend-expect'
import 'jest-canvas-mock'
// Sveltekit Mocks
jest.mock('$app/environment.js', () => ({
amp: false,
browser: false,
dev: true,
mode: 'test',
}))
jest.mock('$app/navigation.js', () => ({
goto: jest.fn(),
}))
// In more recent tests I've started using the "TestHarness" instead of this `svelte` mock with a fake getContext
jest.mock('svelte', () => {
const { writable } = require('svelte/store')
const actualSvelte = jest.requireActual('svelte')
const fakeGetContext = jest.fn((name) => {
if (name === '__svelte__') {
return fakeSvelteKitContext
}
})
const fakeSvelteKitContext = {
page: writable({
path: '/',
query: new URLSearchParams({
offset: '0',
limit: '5',
}),
}),
navigating: writable(false),
}
const mockedSvelteKit = {
...actualSvelte,
getContext: fakeGetContext,
}
return mockedSvelteKit
})
// End Sveltekit mocks
global.ResizeObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
}))