-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
39 lines (33 loc) · 1.21 KB
/
vitest.setup.ts
File metadata and controls
39 lines (33 loc) · 1.21 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
import 'temporal-polyfill-lite/global';
import 'temporal-polyfill-lite/types/global';
import {beforeEach, vi} from 'vitest';
import {config, mount} from '@vue/test-utils';
import {createTestingPinia} from '@pinia/testing';
import resizeObserver from 'resize-observer-polyfill';
import createI18n from '@/i18n';
import en from '@/i18n/en.json';
import router from '@/router';
window.HTMLElement.prototype.scrollIntoView = vi.fn();
window.HTMLElement.prototype.hasPointerCapture = vi.fn();
vi.stubGlobal('ResizeObserver', resizeObserver);
config.global.plugins = [createI18n(en), router];
config.global.directives = {
tippy() {},
};
const dataTestIdPlugin = (wrapper: ReturnType<typeof mount>) => ({
findByTestId: (testId: string) => wrapper.find(`[data-test-id='${testId}']`),
findByText: (selector: string, text: string) =>
wrapper.findAll(selector).find((node) => {
return node.text() === text;
}),
});
config.plugins.VueWrapper.install(dataTestIdPlugin);
vi.mock('canvas-confetti', () => ({
default: () => false,
}));
// Reset handlers after each test
beforeEach(() => {
// Clear local storage so state is fresh for each test
localStorage.clear();
config.global.plugins[2] = createTestingPinia();
});