jovan
@nuxtjs/i18n test errors
I managed to make it work with the setup files in vitest config as you said
This is my setup file:
const i18n = createI18n({
locale: 'en',
legacy: false,
globalInjection: true,
messages: {
en
}
})
config.global.plugins = [i18n]
Thank you.
19 replies
@nuxtjs/i18n test errors
describe('Component', () => {
test('renders all components', async () => {
const wrapper = await mountSuspended(AppSettings, {
global: {
components: mockComponents,
plugins: [i18n]
}
})
Object.keys(mockComponents).forEach((componentName) => {
expect(wrapper.findComponent({ name: componentName }).exists()).toBe(true)
})
}, 50000)
})
19 replies
@nuxtjs/i18n test errors
Hi everyone,
I'm using the @nuxtjs/i18n library in my Nuxt project and am currently writing a test for a Vue component. However, I keep running into the following errors:
"Need to install with app.use function"
"$t is not a function"
My component is fairly simple, rendering translations inside the <template> using $t.
Here’s the basic test I'm working on:
test('renders all child components', () => {
const wrapper = mount(AppSettings, {
global: {
components: mockComponents,
mocks: {
$t: (key: string) => key, // Mocking the i18n $t function
},
},
});
Object.keys(mockComponents).forEach((componentName) => {
expect(wrapper.findComponent({ name: componentName }).exists()).toBe(true);
});
});
I've tried mocking the $t function, but I still get the "Need to install with app.use function" error. Does anyone know why this is happening or how to resolve it?
Thanks!19 replies