-
-
Notifications
You must be signed in to change notification settings - Fork 490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How mock i18n with vitest #3291
Comments
Although I got another issues with the new Update :D In the past we have configured a global i18n mock/instance in the setup.ts file of vitest. // https://github.com/nuxt/test-utils/issues/566#issuecomment-2200984889
import { config } from '@vue/test-utils'
import { createI18n } from 'vue-i18n'
const i18n = createI18n({
legacy: false,
globalInjection: true,
locale: 'de',
missing: (_, key) => key,
})
config.global.plugins.push(i18n) vue-i18n made the use of the useI18n composable much stricter, not to use it outside of a "< setup >" inside a SFC. |
Hello, Your solution, @th1nkgr33n, helped me for the moment – thanks ❤️. My tests are running again, i18n usage in my components is migrated, but I am getting these annoying warnings: I want to use real translations for my tests (or have a config for i18n that is close to the real world), so I need the following config – ideally I want the same config as my real world app is using: const i18n = createI18n({
legacy: false,
globalInjection: true,
locale: "en",
messages: {
en: {
...english,
},
de: {},
},
});
config.global.plugins.push(i18n);
Can you explain this statement in more detail? |
@FruityLeo... The MarkdownEditor removed some stuff. We are in on-going work to remove that warning and if we found a solution for our project, I could post that here. |
Ah ok, got it, thanks. |
Hello,
I've been fighting for a day about the i18n mock with vitest.
Before updating to v9, I make a global mock as follows in
vitest.setup.ts
But since the update, I've tried a number of solutions to make an i18n mock, but I've never succeeded.
I keep getting the following error:
knowing that in my component view. I use the following format:
const { t } = useI18n()
and that my
nuxt.config.ts
isis as follows:
Do you have any solutions ?
The text was updated successfully, but these errors were encountered: