You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is the unit test for my component Home.spec.ts :
importmessagesfrom'@/i18n/messages';importHomeVuefrom'@/projectName/ui/home/Home.vue';import{shallowMount,VueWrapper}from'@vue/test-utils';import{beforeEach,describe,expect,it}from'vitest';import{createI18n}from'vue-i18n';describe('Home',()=>{letwrapper: VueWrapper;beforeEach(()=>{wrapper=shallowMount(HomeVue,{global: {plugins: [createI18n({legacy: false,locale: 'fr',fallbackLocale: 'fr',
messages
})]}});});it('should display a welcome message',()=>{expect(wrapper.find('[data-test="home-welcome"]').text()).toBe('Bienvenue sur mon projet !');});});
And here is the component code (Home.vue) :
<template><div><h1data-test="home-welcome">{{t('home.welcome')}}</h1></div></template><scriptsetuplang="ts">import{ useI18n }from'vue-i18n';const{ t }=useI18n();</script>
messages.ts
constmessage={fr: {home: {welcome: 'Bienvenue sur mon projet !'}},en: {home: {welcome: 'Welcome on my project!'}}}exportdefaultmessage;
In this configuration, if I run the tests, I'm getting this error :
FAIL tests/unit/woundfollowup/ui/home/Home.spec.ts [ tests/unit/projectName/ui/home/Home.spec.ts ]
Error: You need to define an object as the locale message with 'export default'.
❯ generate node_modules/@intlify/bundle-utils/lib/index.cjs:880:13
❯ esbuildPlugin.transform node_modules/@intlify/unplugin-vue-i18n/lib/index.cjs:317:52
❯ Object.transform node_modules/vite/dist/node/chunks/dep-bb8a8339.js:44352:30
❯ loadAndTransform node_modules/vite/dist/node/chunks/dep-bb8a8339.js:55026:29
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm trying to configure vue-i18n and @intlify/unplugin-vue-i18n to work with my vue.js 4 application.
Here what I did so far.
project structure
vite.config.ts
Here is the unit test for my component Home.spec.ts :
And here is the component code (Home.vue) :
messages.ts
In this configuration, if I run the tests, I'm getting this error :
I'm using
Beta Was this translation helpful? Give feedback.
All reactions