Nextjs Middleware Vitest Jsdom

Fix "request.headers must be an instance of Headers" error when testing Next.js middleware with Vitest in jsdom environment. Use when: (1) NextResponse.next() throws "request.headers must be an instance of Headers" in vitest/jsdom, (2) middleware integration tests fail despite NextRequest being constructed correctly, (3) testing locale detection, redirect logic, or cookie handling in Next.js middleware without edge runtime. Covers mocking NextResponse.next() and NextResponse.redirect() to bypass the jsdom/edge-runtime Headers class mismatch while preserving testable .status, .headers, and .cookies.set().

hubeiqiao Updated 0 repo stars

File contents

hubeiqiao/skills commit 123de489e5

Frequently asked questions

npx get-skill add hubeiqiao/nextjs-middleware-vitest-jsdom