From 7d88532aafc1a96835183a5ee1fbd99e845b4b95 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 9 Jan 2024 22:40:08 +0100 Subject: [PATCH] global vikePageContext --- scripts/tests/mock.vikePageContext.ts | 8 ++++++++ src/components/VikeBtn.test.ts | 3 --- vitest.config.ts | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 scripts/tests/mock.vikePageContext.ts diff --git a/scripts/tests/mock.vikePageContext.ts b/scripts/tests/mock.vikePageContext.ts new file mode 100644 index 0000000..f6d266d --- /dev/null +++ b/scripts/tests/mock.vikePageContext.ts @@ -0,0 +1,8 @@ +import { config } from '@vue/test-utils' + +import { vikePageContext } from '#context/usePageContext' + +config.global.provide = { + ...config.global.provide, + [vikePageContext as symbol]: { urlPathname: '/some-url' }, +} diff --git a/src/components/VikeBtn.test.ts b/src/components/VikeBtn.test.ts index 967a773..a204e46 100644 --- a/src/components/VikeBtn.test.ts +++ b/src/components/VikeBtn.test.ts @@ -2,8 +2,6 @@ import { mount } from '@vue/test-utils' import { navigate } from 'vike/client/router' import { describe, it, expect, beforeEach, vi } from 'vitest' -import { vikePageContext } from '#context/usePageContext' - import VikeBtn from './VikeBtn.vue' vi.mock('vike/client/router') @@ -12,7 +10,6 @@ vi.mocked(navigate).mockResolvedValue() describe('VikeBtn', () => { const Wrapper = () => { return mount(VikeBtn, { - global: { provide: { [vikePageContext as symbol]: { urlPathname: '/some-url' } } }, attrs: { href: '/some-path' }, }) } diff --git a/vitest.config.ts b/vitest.config.ts index a038368..e5f398b 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -8,7 +8,7 @@ export default mergeConfig( test: { globals: true, environment: 'happy-dom', - setupFiles: ['scripts/tests/mock.$t.ts', 'scripts/tests/plugin.vuetify.ts'], + setupFiles: ['scripts/tests/mock.$t.ts', 'scripts/tests/mock.vikePageContext.ts', 'scripts/tests/plugin.vuetify.ts'], coverage: { all: true, include: ['src/**/*.{js,jsx,ts,tsx,vue}'],