-
Notifications
You must be signed in to change notification settings - Fork 3
/
jest.setup.js
47 lines (42 loc) · 1.2 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
45
46
47
/* eslint-disable @typescript-eslint/no-var-requires,no-undef */
const { TextDecoder, TextEncoder } = require('util')
require('jest-fetch-mock').enableMocks()
// changes default behavior of fetchMock to use the real 'fetch' implementation and not mock responses
fetchMock.dontMock()
global.TextEncoder = TextEncoder
global.TextDecoder = TextDecoder
jest.mock('@digitalbazaar/http-client', () => {
return {
httpClient: jest.fn()
}
})
jest.mock('got', () => {
return async (url, options) => {
const response = await fetch(url, {
method: options.method,
body: options.body,
headers: {
...options.headers
}
})
if (response.status < 300) {
const body = await response.text()
return { statusCode: response.status, body }
}
return { statusCode: response.status }
}
})
jest.mock('./lib/config', () => {
const host = jest.requireActual('./lib/stub/const').TEST_DOMAIN
const secretPhase = jest.requireActual('./lib/stub/actor').MOCK_SECRET_PHASES
return {
getConfig: jest.fn().mockReturnValue({
serviceName: 'activities.next',
host,
secretPhase,
email: {
serviceFromAddress: '[email protected]'
}
})
}
})