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
@nuxt/test-utils
is not working with useI18n
from @nuxtjs/i18n
#743
Comments
@nuxt/test-utils
is not working with useI18n
from @nuxtjs/i18n
Does it also fail on v3.10.0? I'm hitting (i think) similar errors when updating to |
I think I have similar error on 3.11 as well. Somehow my init of internal refs inside a plugin broke, init has been completed but no init actually happened (my refs are in their initial state). |
@darthf1 I confirm that the error happens on v3.10.0 as well. |
I have found that the below solution works <script setup lang="ts">
const { t } = useNuxtApp().$i18n
</script> |
@StevenPewsey Yes, it works as same as |
Is this beeing looked at? It's currently holding our enterprise back from upgrading. Still present using the latest version |
@indiehjaerta Here is my workaround so far. import { beforeAll, afterAll, vi } from 'vitest';
import { config } from '@vue/test-utils';
import { createI18n } from 'vue-i18n';
beforeAll(() => {
vi.mock('vue-i18n', async (importOriginal) => {
const module = await importOriginal<typeof import('vue-i18n')>();
return { ...module };
});
});
afterAll(() => {
vi.restoreAllMocks();
});
// setup i18n
const i18n = createI18n({
legacy: false,
locale: 'en',
locales: [{ code: 'en', iso: 'en-US', file: 'en-US.yml', name: 'English' }],
messages: {},
missing: (locale: string, key: string) => `trans:__${key}__`,
});
config.global.plugins.push(i18n); |
Environment
Darwin
v18.16.0
3.9.3
3.10.0
2.8.1
pnpm@8.15.0
-
devtools
,modules
@nuxtjs/i18n@8.0.0
-
Reproduction
https://github.com/trandaison/test-utils/tree/main/examples/i18n
Describe the bug
I forked these examples then add a component named
TheHeader.vue
which do useconst { t } = useI18n()
in the setup script.The test will be timeout and unable to run in this case.
If I replace the
useI18n
composition with the$t
function (or don't use any translate function at all) the test will be passed.Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: