-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjest.setup.js
70 lines (62 loc) · 1.51 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* @file This file is used to configure or set up a testing framework before each test.
* If you delete this file, remove `setupFilesAfterEnv` from `jest.config.js`
* Used for __tests__/testing-library.js
*/
import i18n from 'i18next'
import en from 'public/locales/en/translation.json'
import es from 'public/locales/es/translation.json'
import { initReactI18next } from 'react-i18next'
import 'whatwg-fetch'
// Mock MUI license so we can run tests
jest.mock('@mui/x-license-pro', () => ({
useLicenseVerifier: () => 'Valid',
Watermark: () => null,
}))
// we much mock the Article component because it is uses next-mdx-remote that is incomatible with jest
jest.mock('components/common/Resources/Article', () => {
return jest.fn().mockImplementation(() => {
return <div>Mocked Article</div>
})
})
// noinspection JSUnusedGlobalSymbols
global.ResizeObserver = class ResizeObserver {
observe() {
// do nothing
}
unobserve() {
// do nothing
}
disconnect() {
// do nothing
}
}
/**
* Initializes the i18n library for testing.
* @async
* @function
* @returns {Promise<void>}
*/
async function initI18n() {
await i18n
.use(initReactI18next) // passes i18n down to react-i18next
.init({
resources: {
en,
es,
},
lng: 'en',
fallbackLng: 'en',
interpolation: {
escapeValue: false,
},
})
}
/**
* Immediately Invoked Function Expression (IIFE) to initialize i18n.
* @async
* @function
*/
;(async () => {
await initI18n()
})()