-
Notifications
You must be signed in to change notification settings - Fork 71
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
Vue-I18n not loaded #566
Comments
I know your pain because I feel it too. I am trying to put together a test environment for nearly 4 days now. And I thought Codeception with Selenium in a docker was hard. Here is a SO link someone might find interesting: Mock i18n Unfortunately none of the answers in that SO question helps me. I try to mock the i18n. I see no sense in checking for "the right translation" but this is ofcourse opinionated. The strange thing is, that mocking actually sometimes work. But if I hit rerun on the test, it doesn't anymore and I get:
If others want to try, here is my setup which "SOMETIMES" work:
As I said it sometimes work and sometimes not. It could help if you comment out |
Without One thing I would try before changing everything would be to actually initialize i18n like I do now and try to mock the functions of the i18n instance: vi.spyOn(i18n.global, 't').mockImplementation((tKey) => String(tKey)); |
Good luck with that. I am sick and tired of trying. And if you ever get a working real world testing environment, I beg you to share it. Maybe here #137. I also use |
@QozbroQqn I made a minimal stackblitz project with the way I'm working with it. Maybe it helps: https://stackblitz.com/edit/nuxt-starter-bjyxnr |
Thank you. If you have the time and could test vuetify, that would be awesome. Maybe you see something I don't. And is there a reason why you use intlify instead of nuxt i18n module V8? |
I tried some things and they didn't work. I guess there is another (component related) problem in addition to the normal problem, that plugins don't load. Sorry :/
Not really. It was the one that worked at the time I set it up for my project. |
Thank you for your trying. Guess I just have to wait. |
Would you see if 0.6.12 resolved the issue for you? If not, would you provide a reproduction? |
Thank you for your hard work @danielroe. @Floppy012 made a minimal example:https://stackblitz.com/edit/nuxt-starter-bjyxnr You just need to remove the setup file from vitest config and get the following error:
same in my project. Only difference is I am using the nuxt i18n module instead of intlify. Hope that helps. |
@danielroe https://stackblitz.com/edit/nuxt-starter-c57a8p?file=package.json Still does not work. I've made a repro with both cases ( |
I'm also having this issue. I succesfully mocked the |
I tried it with |
Got this working without creating a new instance of i18n. https://stackblitz.com/edit/nuxt-starter-px8r35?file=test%2Fsetup.ts,app.vue,nuxt.config.ts import { config } from '@vue/test-utils';
try {
// For .nuxt.test files reuse the nuxt's i18n instance
const nuxtApp = useNuxtApp();
config.global.plugins.push({
async install(app, ...options) {
const i18n = nuxtApp.vueApp.__VUE_I18N__;
await i18n.install(app, ...options);
},
});
} catch {
// For .test files we don't make i18n available
} It seems weird to me that there's a whole another vue app being created by nuxt that is different than the one created by @vue/test-utils. All vue plugins installed via nuxt modules have to be manually re-installed on the test vue instance. I would've assumed that that part of nuxt's initialization would be stubbed by this module and all plugins would be forwarded to the test app. |
I would welcome ideas or PRs for closer (ideally automatic) integration with |
I'm honestly not sure what I've actually been using vue-test-utils' |
Here's an example of integrating with |
@danielroe The example above is not working if change the global function + <script setup>
+ const { t: $t } = useI18n();
+ </script>
+
<template>
<div>
Hi from @nuxtjs/i18n: {{ $t('hello') }}
</div>
</template> I already open an issue here #743, please have a look when you have time. |
Like mentioned above updating the code using |
I'm currently trying to implement component tests for a component that uses
vue-i18n
and I'm getting this error:I have
@intlify/nuxt3
configured in mynuxt.config.ts
:I'm working around this problem by manually using
createI18n
in my setup file and adding it to the global plugins of vue test-utils:Then, since I'm also testing using
@testing-library/vue
which has another bug, I also have to use the workaround described there to also get the plugin working for testing-library.I know there is nobody to blame but component tests are DX-wise very bad. I have to invest more time into getting the tests to actually work, than writing them :/
The text was updated successfully, but these errors were encountered: