testing

A set of software-testing rules for Vitest, React Testing Library, and Playwright, covering unit, component, integration, and end-to-end tests. TDD means writing a failing test before implementing the behavior.

In plain words
What is it for?
Use it when writing or fixing tests, handling regression bugs, or following TDD or BDD workflows across frontend and application test suites.
Why use it?
It provides consistent testing practices and discourages fragile tests, excessive mocking, and checks tied to internal code details rather than what users can do.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/kok-o/koko-contextos-agents/testing
Clone the repo
git clone --depth 1 https://github.com/kok-o/koko-contextos-agents

Made for: Cursor.

Per session 32 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,357 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00032 $0.01357
Opus 5 $0.00016 $0.00678
Sonnet 5 $0.00006 $0.00271
Haiku 4.5 $0.00003 $0.00136

Measured 2d ago against content hash d0cb96a22215, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

testing scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/testing.mdc · 166 lines

How it starts

The opening of the file, as written. The whole thing — 166 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Skill: testing

Testing

Overview

Testing strategy across unit, component, integration, and end-to-end testing suites using Vitest, React Testing Library, and Playwright.

When to Use

Activate for any task involving unit tests, integration tests, E2E testing, TDD/BDD workflows, or fixing regression bugs.

Rules & Patterns

️ The ContextOS Testing Pyramid

      /\
     /E2E\       10% — Playwright (Critical user journeys, auth, checkout)
    /-----\
   / Integ \     20% — API & Component Integration (RTL + MSW / Supertest)
  /---------\
 /   Unit    \   70% — Pure functions, Domain Entities, Utils (Vitest)
/-------------\

Negative Constraints (What NOT to Do)

  1. NEVER mock internal implementation details: Mock ONLY external I/O boundaries (HTTP network requests via MSW, Database via test containers or in-memory DB).
  2. NEVER test implementation details: In React Testing Library, query by user-facing roles (getByRole, getByLabelText), NEVER by CSS selectors or internal component state.
  3. NEVER write assertions without an expected failure mode: Each test must test a single logical behavior and fail if that behavior breaks.
  4. NEVER leave flaky tests or arbitrary sleep (await delay(1000)): Always use waitFor() or explicit event triggers with timeouts.
  5. NEVER share mutable state between tests: Every test must have isolated state via beforeEach() setup and clean reset.

AAA Standard Pattern

describe('Feature / Unit', () => {
  it('should achieve expected outcome when given specific condition', async () => {
    // 1. ARRANGE
    const user = createTestUser({ role: 'admin' });
    // 2. ACT
    const result = await processOrder(user, sampleCart);
    // 3. ASSERT
    expect(result.status).toBe('confirmed');
  });
});

Code Examples

See EXAMPLES.md for detailed anti-patterns and production testing code.

Validation Checklist

  • Tests follow Arrange-Act-Assert (AAA) structure
  • No brittle CSS selectors or private state inspections
  • Mocks isolated strictly to network/IO boundaries (MSW)
  • Fast execution (< 5s for unit suite) with zero flaky sleeps

Read the full file on GitHub · 166 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 166 lines · 32 tokens per session scan A d0cb96a22215

Subscribe to this mod's changes

testing is a cursor rule published in the GitHub repository kok-o/koko-contextos-agents (2 stars, last pushed 2d ago), licensed MIT. It adds 32 tokens to every session and 1,357 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.