Skip to content

Commit

Permalink
Switch to spy on window.location.href
Browse files Browse the repository at this point in the history
  • Loading branch information
Elweyn committed Mar 27, 2024
1 parent fb0b132 commit cc71ac3
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions presenter/src/components/language/LanguageSelector.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { mount } from '@vue/test-utils'
import { describe, it, expect, beforeEach, vi, beforeAll, afterAll } from 'vitest'
import { describe, it, expect, beforeEach, vi } from 'vitest'

import LanguageSelector from './LanguageSelector.vue'

const { location } = window

const setHrefSpy = vi.fn((href: string) => href)
const locationHrefSetSpy = vi.spyOn(window.location, 'href', 'set')

describe('LanguageSelector', () => {
const Wrapper = () => {
Expand All @@ -16,18 +14,6 @@ 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 @@ -43,7 +29,7 @@ describe('LanguageSelector', () => {
})

it('to en', () => {
expect(setHrefSpy).toHaveBeenCalledWith('/en/some-url')
expect(locationHrefSetSpy).toHaveBeenCalledWith('/en/some-url')
})
})
})

0 comments on commit cc71ac3

Please sign in to comment.