forked from rancher/dashboard
-
Notifications
You must be signed in to change notification settings - Fork 1
/
jest.setup.js
63 lines (54 loc) · 2.07 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
/* eslint-disable no-undef */
import { config } from '@vue/test-utils';
import { directiveSsr as t } from '@shell/plugins/i18n';
import VTooltip from 'v-tooltip';
import VModal from 'vue-js-modal';
import vSelect from 'vue-select';
import { VCleanTooltip } from '@shell/plugins/clean-tooltip-directive.js';
import '@shell/plugins/replaceall';
import ClientOnly from 'vue-client-only';
import Vue from 'vue';
Vue.config.productionTip = false;
Vue.use(VTooltip).use(VModal);
Vue.use(VCleanTooltip);
Vue.component('v-select', vSelect);
Vue.component(ClientOnly.name, ClientOnly);
/**
* Global configuration for Jest tests
*/
beforeAll(() => {
// matchMedia and getContext methods aren't included in jest's version of jsdom for us to mock
// implemented as per jest documentation: https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
Object.defineProperty(window, 'matchMedia', { value: jest.fn().mockImplementation(() => ({ addListener: jest.fn() })) });
Object.defineProperty(HTMLCanvasElement.prototype, 'getContext', {
value: jest.fn().mockImplementation(() => ({
createLinearGradient: jest.fn(),
fillRect: jest.fn(),
getImageData: jest.fn(() => ({ data: [] }))
}))
});
});
/**
* Common initialization for each test, required for resetting states
*/
beforeEach(() => {
// jest.resetModules(); // Use this function inside your test if you need to remove any cache stored
// jest.clearAllMocks(); // Use this function inside your test if you need to reset mocks
jest.restoreAllMocks(); // Use this function inside your test if you need to reset mocks and restore existing functionality
// Mock the $plugin object
config.mocks['$plugin'] = { getDynamic: () => undefined };
config.mocks['$store'] = { getters: { 'i18n/t': jest.fn() } };
config.directives = { t, 'clean-tooltip': VCleanTooltip };
// Overrides some components
// config.stubs['my-component'] = { template: "<div></div> "};
});
/**
* Clean up after each test
*/
afterEach(() => {
});
/**
* Clean up after all tests
*/
afterAll(() => {
});