router-act

Control Next.js router request timing and responses for deterministic end-to-end tests.

142k|31.7k|Updated Oct 5, 2016
One-click install
npx skills add https://github.com/vercel/next.js --skill router-act
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: router-act
Source: https://github.com/vercel/next.js/tree/main/.agents/skills/router-act
Command: npx skills add https://github.com/vercel/next.js --skill router-act

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

End-to-end testing of Next.js router interactions becomes deterministic by controlling the timing and responses of router requests (such as prefetches) and by asserting on outcomes.

Core Features & Use Cases

  • Act API intercepts router requests (prefetches, navigations) and buffers responses until the test scope ends, enabling deterministic assertions.
  • LinkAccordion pattern gates prefetching by toggling link visibility inside an act scope, reducing flakiness.
  • Fake clocks and fixtures simulate time-based scenarios, such as segment-cache staleness and navigation timing.
  • Use cases include validating prefetch timing, navigation flows, and segment-cache behavior in Next.js apps.

Quick Start

Wrap your test scope with act to deterministically control router requests and responses.

Frequently Asked Questions about router-act

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

FAQPage Schema
How do I make Next.js router navigation tests deterministic?

Next.js router navigation tests become deterministic by intercepting router requests and buffering responses until the test scope ends, ensuring assertions do not rely on unpredictable timing.

What is the best way to test prefetch timing in Next.js apps?

Testing prefetch timing in Next.js is best handled by using fake clocks and fixtures to simulate time-based scenarios, allowing precise validation of segment-cache staleness and navigation behavior.

Why does my Next.js end-to-end test flake on client router navigations?

Next.js end-to-end tests flake on client router navigations due to uncontrolled asynchronous prefetch responses; gating link visibility and intercepting requests within an act scope eliminates this flakiness.

How do I assert no pending router requests during a Next.js test?

Asserting no pending router requests during a Next.js test requires using no-requests assertions to verify that all prefetches and navigations have fully resolved within the controlled test scope.

Can I test segment cache behavior in Next.js without real network requests?

Testing segment cache behavior in Next.js without real network requests is possible by using fake clocks and intercepting router requests to simulate and control cache staleness timing.

Does router-act work with the Next.js App Router?

The router-act testing utility is designed specifically for Next.js, intercepting client router navigations, prefetch timings, and segment cache behavior to deliver deterministic end-to-end test outcomes.