fix vuetify setup, allow i18n usage in tests

This commit is contained in:
Ulf Gebhardt 2023-11-16 13:25:27 +01:00
parent 6fbce556a7
commit 91a75b2cff
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
4 changed files with 28 additions and 4 deletions

View File

@ -1,4 +1,4 @@
import { mount } from '@vue/test-utils'
import { mount, config } from '@vue/test-utils'
import { describe, it, expect } from 'vitest'
import ClickCounter from './ClickCounter.vue'
@ -6,8 +6,17 @@ import ClickCounter from './ClickCounter.vue'
describe('clickCounter', () => {
const wrapper = mount(ClickCounter)
it('renders Button with a Counter of 0', () => {
expect(wrapper.find('v-btn').exists()).toBeTruthy()
expect(wrapper.find('.v-btn').exists()).toBeTruthy()
expect(wrapper.text()).toBe("$t('counter') 0")
})
it('has default Translation German', () => {
const $Backup = config.global.mocks.$t
config.global.mocks.$t = config.global.mocks.i18n$t
const wrapper = mount(ClickCounter)
expect(wrapper.text()).toBe('Zähler 0')
config.global.mocks.$t = $Backup
})
})

View File

@ -1,6 +1,6 @@
// tests/unit.setup.ts
import { config } from '@vue/test-utils'
config.global.mocks = {
...config.global.mocks,
$t: (tKey: string) => "$t('" + tKey + "')", // just return translation key
}

15
tests/plugin.vuetify.ts Normal file
View File

@ -0,0 +1,15 @@
import { config } from '@vue/test-utils'
// eslint-disable-next-line import/no-relative-parent-imports
import i18n from '../renderer/i18n'
// eslint-disable-next-line import/no-relative-parent-imports
import vuetify from '../renderer/vuetify'
config.global.plugins.push(vuetify(i18n))
config.global.mocks = {
...config.global.mocks,
i18n$t: i18n.global.t,
i18n$d: i18n.global.d,
i18n$n: i18n.global.n,
}

View File

@ -8,7 +8,7 @@ export default mergeConfig(
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['tests/unit.setup.ts'],
setupFiles: ['tests/mock.$t.ts', 'tests/plugin.vuetify.ts']
/*
server: {
deps: {