forked from cowprotocol/cowswap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.ts
More file actions
45 lines (36 loc) · 1.22 KB
/
jest.setup.ts
File metadata and controls
45 lines (36 loc) · 1.22 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
import { config } from 'dotenv'
import 'jest-styled-components' // include style rules in snapshots
import fetchMock from 'jest-fetch-mock' // Mocks `fetch` calls in unittests
import { Readable } from 'stream'
import { TextDecoder, TextEncoder } from 'util'
// For simplicity, we will use CowSwap default .env for all projects and libs
config({ path: __dirname + '/apps/cowswap-frontend/.env' })
if (typeof global.TextEncoder === 'undefined') {
global.ReadableStream = Readable as unknown as typeof globalThis.ReadableStream
global.TextEncoder = TextEncoder
global.TextDecoder = TextDecoder as typeof global.TextDecoder
}
fetchMock.dontMock()
jest.mock('react-markdown', () => () => null)
jest.mock('lottie-react', () => () => null)
jest.mock('quick-lru', () => {
return {
__esModule: true,
default: class MockQuickLRU extends Map {
constructor() {
super()
}
},
}
})
jest.mock('@cowprotocol/analytics', () => ({
...jest.requireActual('@cowprotocol/analytics'),
initGtm: jest.fn().mockImplementation(() => ({
sendEvent: jest.fn(),
})),
__resetGtmInstance: jest.fn(),
}))
beforeEach(() => {
const { __resetGtmInstance } = require('@cowprotocol/analytics')
__resetGtmInstance()
})