From 6e70e04bcc871c85fcb5466c9e9ec8e781be2995 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 26 Mar 2024 19:24:05 +0100 Subject: [PATCH] fix test --- .../language/LanguageSelector.test.ts | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/presenter/src/components/language/LanguageSelector.test.ts b/presenter/src/components/language/LanguageSelector.test.ts index 788865856f..8029222275 100644 --- a/presenter/src/components/language/LanguageSelector.test.ts +++ b/presenter/src/components/language/LanguageSelector.test.ts @@ -1,10 +1,12 @@ import { mount } from '@vue/test-utils' -import { describe, it, expect, beforeEach } from 'vitest' - -import i18n from '#plugins/i18n' +import { describe, it, expect, beforeEach, vi, beforeAll, afterAll } from 'vitest' import LanguageSelector from './LanguageSelector.vue' +const { location } = window + +const setHrefSpy = vi.fn((href: string) => href) + describe('LanguageSelector', () => { const Wrapper = () => { return mount(LanguageSelector, { @@ -14,6 +16,18 @@ describe('LanguageSelector', () => { let wrapper: ReturnType let vSelect: ReturnType + beforeAll(() => { + window.location = {} as Location + Object.defineProperty(window.location, 'href', { + get: vi.fn(), + set: setHrefSpy, + }) + }) + + afterAll(() => { + window.location = location + }) + beforeEach(() => { wrapper = Wrapper() vSelect = wrapper.findComponent({ name: 'v-select' }) @@ -29,7 +43,7 @@ describe('LanguageSelector', () => { }) it('to en', () => { - expect(i18n.global.locale.value).toBe('en') + expect(setHrefSpy).toHaveBeenCalledWith('/en/some-url') }) }) })