forked from activist-org/activist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.ts
46 lines (37 loc) · 1.27 KB
/
setup.ts
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
// SPDX-License-Identifier: AGPL-3.0-or-later
import { config } from "@vue/test-utils";
import { createPinia, defineStore, setActivePinia } from "pinia";
import { createI18n } from "vue-i18n";
import en from "~/i18n/en-US.json" assert { type: "json" };
import type { UseColorModeFn } from "~/test/vitest-globals";
// Set up Pinia.
setActivePinia(createPinia());
// Auto-import version of define store doesn't exist in the test env.
// @ts-expect-error Can't type this due to conflict with Nuxt.
globalThis.defineStore = defineStore;
// Set up Color Mode mock.
const useColorModeFn: UseColorModeFn = () => ({
preference: "dark",
value: "dark",
});
globalThis.useColorModeMock = vi.fn(useColorModeFn);
// Set up I18n.
// https://github.com/nuxt-modules/i18n/issues/2637#issuecomment-2233566361
const i18n = createI18n({
legacy: false,
locale: "en",
fallbackLocale: "en",
messages: Object.assign({ en }),
});
config.global.plugins.push(i18n);
afterEach(() => {
// Clean up Pinia.
setActivePinia(createPinia());
// Clean up color mode mock.
globalThis.useColorModeMock.mockReset();
globalThis.useColorModeMock.mockImplementation(useColorModeFn);
});
afterAll(() => {
// @ts-expect-error type This will be present during the tests.
delete globalThis.useColorModeMock;
});