-
Notifications
You must be signed in to change notification settings - Fork 91
/
jest.setup.js
44 lines (36 loc) · 1.39 KB
/
jest.setup.js
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
import '@testing-library/jest-dom/extend-expect'
import FDBFactory from 'fake-indexeddb/build/FDBFactory'
import FDBKeyRange from 'fake-indexeddb/build/FDBKeyRange'
import { Crypto } from '@peculiar/webcrypto'
import { ResizeObserver } from 'd2l-resize-aware/resize-observer-module.js'
import { deleteDatabase } from '../src/database/databaseLifecycle'
if (!global.performance) {
global.performance = {}
}
if (!global.performance.mark) {
global.performance.mark = () => {}
}
if (!global.performance.measure) {
global.performance.measure = () => {}
}
jest.mock('node-fetch', () => require('fetch-mock-jest').sandbox())
jest.setTimeout(60000)
global.fetch = require('node-fetch')
global.Response = fetch.Response
global.crypto = new Crypto()
global.ResizeObserver = ResizeObserver
process.env.NODE_ENV = 'test'
global.IDBKeyRange = FDBKeyRange
global.indexedDB = new FDBFactory()
// TODO: figure out how to get the styles into Jest. For now it doesn't really
// matter because none of the tests rely on visibility checks etc.
jest.mock('emoji-picker-element-styles', () => '', { virtual: true })
beforeAll(() => {
jest.spyOn(global.console, 'log').mockImplementation()
jest.spyOn(global.console, 'warn').mockImplementation()
})
afterEach(async () => {
// fresh indexedDB for every test
const dbs = await global.indexedDB.databases()
await Promise.all(dbs.map(({ name }) => deleteDatabase(name)))
})