nuxt-i18n-micro: Errors with vitest
Describe the bug I’m struggling to create vitest unit tests for pages/components that use $t
To Reproduce Steps to reproduce the behavior:
- Go to https://stackblitz.com/edit/github-mag9gj-h2v1xa?file=README.md,app%2Fpages%2Findex.vue,package.json,locales%2Fen-GB.json,nuxt.config.ts,app%2Fcomponents%2FTestComponent.vue,app%2Fcomponents%2FTestComponent.nuxt.spec.ts,tests%2Fvitest.unit-config.ts
- Run
npm run test - See errors with loading _locals and $t is not a function
Errors
[nuxt] error caught during app initialization FetchError: [GET] "/_locales/general/en-GB/data.json?v=1733229424546": 404 Cannot find any path matching /_locales/general/en-GB/data.json?v=1733229424546.
at $fetch2 (file:///home/projects/github-mag9gj-tnstob/node_modules/ofetch/dist/shared/ofetch.03887fc3.mjs:333:15)
at loadTranslationsForRoute (/home/projects/github-mag9gj-tnstob/node_modules/nuxt-i18n-micro/dist/runtime/plugins/01.plugin.js:232:20)
at eval (/home/projects/github-mag9gj-tnstob/node_modules/nuxt-i18n-micro/dist/runtime/plugins/01.plugin.js:255:118)
at applyPlugin (/home/projects/github-mag9gj-tnstob/node_modules/nuxt/dist/app/nuxt.js:146:25)
at executePlugin (/home/projects/github-mag9gj-tnstob/node_modules/nuxt/dist/app/nuxt.js:183:9)
at Module.applyPlugins (/home/projects/github-mag9gj-tnstob/node_modules/nuxt/dist/app/nuxt.js:197:5)
at initApp (/home/projects/github-mag9gj-tnstob/node_modules/nuxt/dist/app/nuxt-vitest-app-entry.js:55:7)
TypeError: $setup.$t is not a function
❯ Proxy._sfc_render components/TestComponent.vue:23:76
5| <template>
6| <div>Test from component: {{ $t('welcome') }}</div>
7| </template>
| ^
I’m not sure if this is an issue with the library or something I’m going to have to manually mock on reflection.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (6 by maintainers)
All working great, thank you! Loving the library.
fixed v1.38.5