nextjs-middleware-vitest-jsdom

Community

Test Next.js middleware in Vitest/jsdom

Authorhubeiqiao
Version1.0.0
Installs0

System Documentation

What problem does it solve?

This Skill resolves the "request.headers must be an instance of Headers" error encountered when testing Next.js middleware with Vitest in a jsdom environment, enabling seamless middleware integration testing.

Core Features & Use Cases

  • Mocking NextResponse: Bypasses the jsdom/edge-runtime Headers class mismatch by mocking NextResponse.next() and NextResponse.redirect().
  • Preserves Testability: Allows testing of status, headers, and cookies without altering the core NextRequest object.
  • Use Case: Debugging and ensuring the correct functioning of locale detection, redirect logic, or cookie handling within your Next.js middleware without relying on the edge runtime.

Quick Start

Apply the provided TypeScript mock to your Vitest setup before importing your middleware.

Dependency Matrix

Required Modules

None required

Components

references

💻 Claude Code Installation

Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.

Please help me install this Skill:
Name: nextjs-middleware-vitest-jsdom
Download link: https://github.com/hubeiqiao/skills/archive/main.zip#nextjs-middleware-vitest-jsdom

Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
View Source Repository

Agent Skills Search Helper

Install a tiny helper to your Agent, search and equip skill from 223,000+ vetted skills library on demand.