For your unit tests, @nuxt/test-utils
lets you opt-in to a Nuxt environment by adding .nuxt.
to the filename of your test:
./tests/MyComponent.nuxt.test.ts
You can also add a special comment at the top of the file:
@vitest-environment nuxt
Or enable the environment for all Vitest tests in your config:
// vitest.config.tsimport { defineVitestConfig } from '@nuxt/test-utils/config';export default defineVitestConfig({test: {environment: 'nuxt'},};