mirror of
https://github.com/IT4Change/boilerplate-frontend.git
synced 2025-12-13 07:35:53 +00:00
fix vuetify setup, allow i18n usage in tests
This commit is contained in:
parent
6fbce556a7
commit
91a75b2cff
@ -1,4 +1,4 @@
|
|||||||
import { mount } from '@vue/test-utils'
|
import { mount, config } from '@vue/test-utils'
|
||||||
import { describe, it, expect } from 'vitest'
|
import { describe, it, expect } from 'vitest'
|
||||||
|
|
||||||
import ClickCounter from './ClickCounter.vue'
|
import ClickCounter from './ClickCounter.vue'
|
||||||
@ -6,8 +6,17 @@ import ClickCounter from './ClickCounter.vue'
|
|||||||
describe('clickCounter', () => {
|
describe('clickCounter', () => {
|
||||||
const wrapper = mount(ClickCounter)
|
const wrapper = mount(ClickCounter)
|
||||||
|
|
||||||
|
|
||||||
it('renders Button with a Counter of 0', () => {
|
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")
|
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
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
// tests/unit.setup.ts
|
|
||||||
import { config } from '@vue/test-utils'
|
import { config } from '@vue/test-utils'
|
||||||
|
|
||||||
config.global.mocks = {
|
config.global.mocks = {
|
||||||
|
...config.global.mocks,
|
||||||
$t: (tKey: string) => "$t('" + tKey + "')", // just return translation key
|
$t: (tKey: string) => "$t('" + tKey + "')", // just return translation key
|
||||||
}
|
}
|
||||||
15
tests/plugin.vuetify.ts
Normal file
15
tests/plugin.vuetify.ts
Normal 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,
|
||||||
|
}
|
||||||
@ -8,7 +8,7 @@ export default mergeConfig(
|
|||||||
test: {
|
test: {
|
||||||
globals: true,
|
globals: true,
|
||||||
environment: 'jsdom',
|
environment: 'jsdom',
|
||||||
setupFiles: ['tests/unit.setup.ts'],
|
setupFiles: ['tests/mock.$t.ts', 'tests/plugin.vuetify.ts']
|
||||||
/*
|
/*
|
||||||
server: {
|
server: {
|
||||||
deps: {
|
deps: {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user