Nuxt & Universal SSR (50 Qs)•Part 3: Advanced Internals, Performance & Production (Senior / Staff)
How do you test Nuxt 3 applications with `@nuxt/test-utils`?
senior LevelCode ExampleFormsPerformanceVue & Nuxt
In Simple Words:
@nuxt/test-utils integrates with Vitest and Playwright to test Nuxt applications in real SSR runtime environments:
- Unit test composables within Nuxt context (
mockNuxtImport). - Spin up real test server instances with
setup({ server: true }). - Fetch SSR HTML using
$fetch('/')and assert rendered elements.
typescript
import { describe, it, expect } from 'vitest';
import { setup, $fetch } from '@nuxt/test-utils/e2e';
describe('Home Page SSR', async () => {
await setup({ server: true });
it('renders server-side title correctly', async () => {
const html = await $fetch('/');
expect(html).toContain('<h1>Welcome to Enterprise Nuxt</h1>');
});
});