router-act
Router Act Testing
Use this skill when writing or modifying tests that involve prefetch requests, client router navigations, or the segment cache. The createRouterAct utility from test/lib/router-act.ts lets you assert on prefetch and navigation responses in an end-to-end way without coupling to the exact number of requests or the protocol details. This is why most client router-related tests use this pattern.
When NOT to Use act
Don't bother with act if you don't need to instrument the network responses — either to control their timing or to assert on what's included in them. If all you're doing is waiting for some part of the UI to appear after a navigation, regular Playwright helpers like browser.elementById(), browser.elementByCss(), and browser.waitForElementByCss() are sufficient.
Core Principles
- Use
LinkAccordionto control when prefetches happen. Never let links be visible outside anactscope. - Prefer
'no-requests'whenever the data should be served from cache. This is the strongest assertion — it proves the cache is working. - Avoid retry/polling timers. The
actutility exists specifically to replace inherently flaky patterns likeretry()loops orsetTimeoutwaits for network activity. If you find yourself wanting to poll, you're probably not usingactcorrectly. - Avoid the
blockfeature. It's prone to false negatives. Preferincludesand'no-requests'assertions instead.
Act API
Config Options
More from vercel/next.js
update-docs
This skill should be used when the user asks to "update documentation for my changes", "check docs for this PR", "what docs need updating", "sync docs with code", "scaffold docs for this feature", "document this feature", "review docs completeness", "add docs for this change", "what documentation is affected", "docs impact", or mentions "docs/", "docs/01-app", "docs/02-pages", "MDX", "documentation update", "API reference", ".mdx files". Provides guided workflow for updating Next.js documentation based on code changes.
2.4Kauthoring-skills
>
982runtime-debug
>
949react-vendoring
>
909flags
>
867dce-edge
>
810