Conversation
danielroe
approved these changes
Feb 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
👀 Highlights
We're releasing Nuxt Test Utils v4, with support for Vitest v4. 🚀
Better mocking support
The biggest improvement in this release is how mocking works. Nuxt initialization has been moved from
setupFilesto thebeforeAllhook (#1516), which meansvi.mockandmockNuxtImportcalls now take effect before Nuxt starts. This fixes a long-standing issue where mocks for composables used in middleware or plugins wouldn't apply reliably (#750, #836, #1496).On top of that,
mockNuxtImportnow passes the original implementation to the factory function (#1552), making partial mocking much more natural:registerEndpointimprovementsregisterEndpointnow works correctly with query parameters in URLs (#1560), and endpoints registered in setup files are no longer lost when modules reset (#1549).🚧 Migration
@nuxt/test-utilsv4 contains a few breaking changes, almost all related to requiring at least vitest v4 as a peer dependency (if you are using vitest). It replacesvite-nodewith Vite's native Module Runner and simplifies pool configuration.This will mean improvements for test performance and mocking, but does require some changes to your test code.
Tip
Most of the changes below are straightforward. The biggest thing to watch out for is code that runs at the top level of a
describeblock — see below.Update your dependencies
Update
vitestand its companion packages together:{ "devDependencies": { - "@nuxt/test-utils": "^3.x", - "vitest": "^3.x", - "@vitest/coverage-v8": "^3.x" + "@nuxt/test-utils": "^4.0", + "vitest": "^4.0", + "@vitest/coverage-v8": "^4.0" } }Peer dependencies
We've tightened peer dependency ranges. You may need to update some of these:
vitest^3.2.0^4.0.2happy-dom*>=20.0.11jsdom*>=27.4.0@jest/globals^29.5.0 || >=30.0.0>=30.0.0@cucumber/cucumber^10.3.1 || >=11.0.0>=11.0.0@testing-library/vue^7.0.0 || ^8.0.1^8.0.1Vitest v4 migration
The rest of the changes come from vitest v4 itself.
describeblocks run during collectionThis is the change that might require most change in your tests. In vitest v4,
describecallback bodies execute during test collection, before the Nuxt test environment has been set up. This means composables called at the top level of adescribeblock will fail with[nuxt] instance unavailable.This applies to
useRouter(),useNuxtApp(),useRoute(), and any other Nuxt composable or auto-import.Tip
If you only need the value within individual tests,
beforeEachor directly within the test works too.Stricter mock exports
If you use
vi.mockwith a factory function, accessing an export that the factory doesn't return will now throw an error instead of silently returningundefined.Note
If you're mocking a virtual module (like
#build/nuxt.config.mjs) whereimportOriginalcan't resolve the real module, you might need to explicitly list all accessed exports in your mock factory.Other changes
For the full list, see the vitest v4 migration guide.
👉 Changelog
compare changes
🚀 Enhancements
mockNuxtImportfactory (#1552)beforeAllhook (#1516)🩹 Fixes
registerEndpointwith query params (#1560)nextTickimport (#1563)💅 Refactors
@nuxt/devtools-kitfor devtools hooks (426e0b537)📖 Documentation
🏡 Chore
app-vitestfollow advised setup guidelines (#1542).nuxtrc(b4021dee4)✅ Tests
beforeAllhook (#1516)❤️ Contributors