Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
ulfgebhardt committed Mar 26, 2024
1 parent 48b4a61 commit 6e70e04
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions presenter/src/components/language/LanguageSelector.test.ts
Original file line number Diff line number Diff line change
@@ -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, {
Expand All @@ -14,6 +16,18 @@ describe('LanguageSelector', () => {
let wrapper: ReturnType<typeof Wrapper>
let vSelect: ReturnType<typeof wrapper.findComponent>

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' })
Expand All @@ -29,7 +43,7 @@ describe('LanguageSelector', () => {
})

it('to en', () => {
expect(i18n.global.locale.value).toBe('en')
expect(setHrefSpy).toHaveBeenCalledWith('/en/some-url')
})
})
})

0 comments on commit 6e70e04

Please sign in to comment.