NuxtN
Nuxt14mo ago
ægteemil

Testing with i18n and vitest

Hey. I have a simple component that uses $t for translations. I'm trying to write a simple test, but it's failing.
describe('UserSignInForm', () => {
    it('renders', async () => {
        const component = await mountSuspended(UserSignInForm);
        expect(component.html()).toMatchSnapshot();
    });
});

I've tried a few solutions that I found online, but none of them seem to work. The error:
SyntaxError: Need to install with `app.use` function
 ❯ Module.createCompileError ../node_modules/@intlify/message-compiler/dist/message-compiler.mjs:78:19
     76|         : code;
     77|     const error = new SyntaxError(String(msg));
     78|     error.code = code;
       |                   ^
     79|     if (loc) {
     80|         error.location = loc;
 ❯ createI18nError ../node_modules/vue-i18n/dist/vue-i18n.mjs:81:34
 ❯ Module.useI18n ../node_modules/vue-i18n/dist/vue-i18n.mjs:2184:15
 ❯ setup components/user/sign-in-form/UserSignInForm.vue:19:19
 ❯ wrappedSetup ../node_modules/@nuxt/test-utils/dist/runtime-utils/index.mjs:96:28
 ❯ clonedComponent.setup ../node_modules/@nuxt/test-utils/dist/runtime-utils/index.mjs:161:48
 ❯ callWithErrorHandling ../node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:200:19
 ❯ setupStatefulComponent ../node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7848:25
 ❯ setupComponent ../node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7809:36
 ❯ mountComponent ../node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5159:7
Was this page helpful?