Nextjs Testing
Write Jest or Vitest unit tests with React Testing Library and Playwright E2E tests for Next.js projects. Use when testing components with RTL, mocking APIs with MSW, or creating Playwright user flow tests.
Unsigned, install at your own risk
UnverifiedThis skill has no cryptographic signature attached. We can't verify the contents match what the publisher intended.
Install this skill
No account required. Pick your tool, or use the command that detects it for you.
Run in your terminal. It detects your AI tool.
npx @skills-hub-ai/cli install multi-language-standards-nextjs-testingManual setup by platform
Claude Code
~/.claude/skills/multi-language-standards-nextjs-testing/SKILL.md
Instructions
Next.js Testing
Priority: P1 (HIGH)
Universal anti-slop rules (naming, identity fixtures, tautologies, skip/focus, mock echoing, bug-first lock, sleeps,
shallow assertions, coverage): anti-slop-rules.md. Only Next.js
deltas follow.
Core Rule Anchors
[WEB-TEST-02..04]Core Web Standards: Accessible roles (getByRole), no prop/state inspection, and MSW network mocking
are owned by the canonical web rules inreact-testing; naming is canonical A11.[WEB-TEST-06]Ban Static Artifact Pinning & Twin.test.jsSuites: Never assert staticprint(GQL)query text or
.loc.source.bodysubstrings (GUARD-TS-STATIC-PINNING); test the hook or query component. Never loop
Object.keys(locales/*.json)or asserttypeof en[k] === 'string'; assert rendered text viafindByText/getByRole.
Never keep<stem>.test.ts(x)beside a legacy<stem>.test.js(x)(GUARD-TS-DUAL-EXT); migrate it. Ban pass-through mock
echoes (expect(wrapper()).toBe(X)without business transformations).
Test Runner & Workflow
- Existing projects (Pages Router / legacy): Jest (
jest@29+babel-jest+jest-environment-jsdom). - New projects (App Router): Vitest for speed and native ESM.
- E2E Testing: Playwright for full user flows (login, checkout).
Implementation Guidelines
- Unit & Component: Jest or Vitest with RTL, AAA; reuse existing companion test files.
- Interactions & Selectors:
userEvent(async) for actions;getByRole/findByRolefor accessibility;data-testidonly
as fallback. - Networking: MSW handlers at API boundaries for deterministic component/unit tests; real network only in Playwright E2E.
- TS Hygiene: Apply canonical rule A6 (
GUARD-TS-FLOATING-ASSERT,GUARD-TS-CATCH-ONLY,
GUARD-TS-CONDITIONAL-ASSERT,GUARD-TS-SELF-MOCK). - No Hard Timeouts: Ban
setTimeoutin unit tests (GUARD-REACT-02); banpage.waitForTimeoutin Playwright
(GUARD-E2E-01). Use web-first assertions (await expect(locator).toBeVisible()) orfindBy*. - Reporting: Generate JSON coverage reports for CI gates; verify risk-weighted behavioral paths, not percentage padding.
Anti-Patterns
- Static pinning & twin suites (
[WEB-TEST-06]):GUARD-TS-STATIC-PINNINGregex pinning, locale JSON key loops,
GUARD-TS-DUAL-EXTsidecars, and pass-through mock echoes. - Hard sleep calls (
GUARD-REACT-02/GUARD-E2E-01):setTimeoutin unit tests,page.waitForTimeoutin E2E. - Unisolated network in unit tests: Use MSW handlers; no external network.
- Implementation testing: Test user behavior, not internal component methods.
- Global state leakage: Reset MSW handlers and mocks after each test.
References
- Next.js Test Patterns
Security
Reviews (0)
Related skills
Browse all →More from Multi-Language Standards
View source →More Build skills
Browse category →Frequently asked questions about nextjs-testing
What does the nextjs-testing skill do?
Write Jest or Vitest unit tests with React Testing Library and Playwright E2E tests for Next.js projects. Use when testing components with RTL, mocking APIs with MSW, or creating Playwright user flow tests. It's a reusable SKILL.md instruction set that loads into your AI coding assistant on demand, no prompt engineering, no copy-pasting every session.
How do I install the nextjs-testing skill?
Run `npx @skills-hub-ai/cli install multi-language-standards-nextjs-testing` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/multi-language-standards-nextjs-testing/ for Claude Code or ~/.cursor/skills/ for Cursor with --target cursor) and adds it to your project's .skills.json lockfile.
Which AI tools does nextjs-testing work with?
nextjs-testing runs in Claude Code. It follows the open Agent Skills standard (SKILL.md), so the same skill works in every supported tool without modification.
Is the nextjs-testing skill free?
Yes. Every skill on skills-hub.ai is free and open-source. There are no premium tiers, paywalls, or usage limits. You only pay for whatever AI assistant you're already using.
How do I use nextjs-testing after installing it?
In Claude Code, type `/multi-language-standards-nextjs-testing` (or whatever slash command the skill registers) and the AI follows the skill's instructions immediately. You can also reference it by name in natural language, your AI loads the skill into context when relevant.
Can I share the nextjs-testing skill with my team?
Yes. Commit your project's .skills.json lockfile and teammates run `npx @skills-hub-ai/cli install` (no args) to install every skill at the exact version you pinned. Organization-scoped installs work via skills-hub.ai organizations.