-
Notifications
You must be signed in to change notification settings - Fork 5
/
jest.init.js
106 lines (93 loc) · 2.17 KB
/
jest.init.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* This file contains the initialization for test cases.
* It is being run from jest.config.js as a setupFile.
* It gets loaded before the tests are run.
*/
import { config } from "@vue/test-utils";
import Toast from "vue-toastification";
import VueTooltip from "vue-tippy";
import VueClickAway from "vue3-click-away";
import VueProgressBar from "@aacassandra/vue3-progressbar";
import mixpanel from "mixpanel-browser";
import "offline-js";
mixpanel.init(process.env.VUE_APP_MIXPANEL_PROJECT_TOKEN);
const $mixpanel = mixpanel;
import router from "@/router";
const $router = router;
import store from "@/store";
const $store = store;
import i18n from "@/services/Localisation/i18n.js";
const $t = (msg) => i18n.global.t(msg);
const $i18n = i18n;
// inline-svg stub
const InlineSvg = {
template: "<img />",
};
const $Progress = {
start: jest.fn(),
finish: jest.fn(),
template: "<div></div>",
};
// stub for <transition> tags
const transition = {
template: "<div></div>",
};
// stub for $gAuth
const $gAuth = {
signIn: jest.fn(),
instance: 1,
};
config.global = {
plugins: [Toast, store, VueProgressBar],
mocks: {
$mixpanel,
$router,
$t,
$store,
$i18n,
$Progress,
$gAuth,
},
directives: {
tooltip: VueTooltip,
clickAway: VueClickAway,
},
stubs: {
InlineSvg: InlineSvg,
transition: transition,
},
};
// mock document
Object.defineProperty(document, "currentScript", {
value: document.createElement("script"),
});
// mock window modules
Object.defineProperty(window, "matchMedia", {
writable: true,
value: jest.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(), // deprecated
removeListener: jest.fn(), // deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
Object.defineProperty(window, "open", {
writable: true,
value: jest.fn(),
});
// mock getBoundingClientRect
global.document.getElementById = jest.fn(() => ({
getBoundingClientRect: jest.fn(() => {
return {
width: 100,
height: 100,
};
}),
setAttribute: jest.fn(() => {
return;
}),
}));