test-utils
test-utils copied to clipboard
Nuxt 4 + Layers breaks Nuxt Test Utils
Environment
- Operating System: Linux
- Node Version: v20.16.0
- Nuxt Version: 3.17.2
- CLI Version: 3.25.0
- Nitro Version: 2.11.11
- Package Manager: [email protected]
- Builder: -
- User Config: modules, devtools, compatibilityDate
- Runtime Modules: @nuxt/test-utils/[email protected]
- Build Modules: -
Reproduction
Github repo: https://github.com/wuiyang/nuxt-layer-test-bug Stackblitz: https://stackblitz.com/~/github.com/wuiyang/nuxt-layer-test-bug
Describe the bug
When project root is using Nuxt 4 version (via config future.compatibilityVersion = 4), nuxt test utils would not work on layers within same project.
The unit test would run without console error log, but the test report would show there is an error:
TypeError: Cannot read properties of undefined (reading 'vueApp')
When project root is not using Nuxt 4 version, the nuxt test utils would work as expected. See reproduction repo:
- Github: https://github.com/wuiyang/nuxt-layer-test-bug/tree/working-without-nuxt-4
- Stackblitz: https://stackblitz.com/~/github.com/wuiyang/nuxt-layer-test-bug/tree/working-without-nuxt-4?file=package.json
Additional context
No response
Logs
abc@efac4cbfa0a5:/..../nuxt-layer-test-bug$ npx vitest run --coverage
Vitest "environmentMatchGlobs" is deprecated. Use "workspace" to define different configurations instead.
HTML Report is generated
You can run npx vite preview --outDir ../test-reports/unit-test to see the test results.
Looks like it's working fine
Node 22, pnpm 8
"devDependencies": {
"@nuxt/test-utils": "^3.19.1",
"@vitest/coverage-v8": "^3.1.4",
"@vitest/ui": "^3.1.4",
"@vue/test-utils": "^2.4.6",
"happy-dom": "^17.5.6",
"nuxt": "^3.17.4",
"vitest": "^3.1.4",
"vite": "^6.3.5",
"vue": "^3.5.16"
},