test-middleware

Test middleware authentication, validation, and routing with mock HTTP contexts.

1|Updated May 21, 2025
One-click install
npx skills add https://github.com/madooei/backend-template --skill test-middleware
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: test-middleware
Source: https://github.com/madooei/backend-template/tree/main/.claude/skills/test-middleware
Command: npx skills add https://github.com/madooei/backend-template --skill test-middleware

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides structured guidance for testing authentication, validation, and other middleware by creating deterministic test contexts and mock services.

Core Features & Use Cases

  • Mock authentication and request context for middleware.
  • Verify next() behavior and error handling.
  • Use with Vitest to ensure middleware correctness across scenarios.

Quick Start

Run the middleware tests with your project's test runner to execute middleware test suites and verify behavior.

Frequently Asked Questions about test-middleware

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test Hono middleware logic using mock HTTP contexts?

Testing Hono middleware involves creating deterministic mock HTTP contexts and dependency-injected services to verify authentication, validation, and routing behavior across scenarios. This approach ensures structured assertions exercise next() invocation and error handling.

What is the best way to verify next() behavior and error handling in validation middleware?

Verifying next() behavior in validation middleware requires structured assertions and test doubles to exercise error handling. By mocking the request context, developers can deterministically confirm next() is invoked correctly or errors are thrown as expected.

Can I use Vitest to test authentication middleware with mock services?

Yes, you can use Vitest to test authentication middleware by applying mock services and test doubles. Vitest executes the middleware test suites to ensure correctness across various scenarios by validating deterministic mock HTTP contexts.

Does test-middleware work with server-side routing pipelines without external dependencies?

Yes, test-middleware works with server-side routing pipelines without external dependencies. It uses dependency injection and mock services to validate middleware behavior, ensuring deterministic test contexts across various pipelines.

Why does my middleware test fail when mocking the request context?

Middleware tests fail when mock HTTP contexts lack proper dependency injection or structured assertions. Ensure test doubles accurately reflect the authentication and validation logic to properly exercise next() invocation and error handling.