write-frontend-tests
Skill1 starsChanged 5 months agoMITView on GitHub
Use when writing frontend tests — a test-worthiness gate first (no 1:1 per-file test mirroring), then Jest + React Testing Library for components/hooks/utils that earn a test, and Cypress + Cucumber for e2e user flows. Where tests live, what to test, mocking the router, and the lint/type/test gates. React/Next.js reference.
3 other projects use a version of this.
Adopted by
Most recently taken up by
- Significant-Gravitas/AutoGPTtheir own version, first seen Nov 4, 2026
- a-novel-kit/stacktheir own version, first seen Oct 13, 2026
- jpoindexter/theft-kittheir own version, first seen May 20, 2026
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 3
- Significant-Gravitas/AutoGPT★ 188ksame name
- a-novel-kit/stack★ 2same name
- jpoindexter/theft-kit★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository40 other files it gives its agents.
- authoring-project-skillsSkill
- background-jobs-and-cachingSkill
- code-conventionsSkill
- containerize-and-ship-a-serviceSkill
- database-migrationsSkill
- design-an-error-modelSkill
- git-flowSkill
- handle-files-frontendSkill
- import-data-from-csvSkill
- integrate-external-servicesSkill
- integrate-identity-providersSkill
- integrate-internal-servicesSkill
- keep-service-memory-leanSkill
- operate-ecs-services-safelySkill
- prevent-secret-and-pii-leaksSkill
- release-safetySkill
- render-transactional-emailsSkill
- rules-backendSkill
- rules-code-styleSkill
- rules-debuggingSkill
- rules-gitSkill
- rules-infraSkill
- rules-pr-reviewSkill
- rules-shippingSkill
- rules-workflowSkill
- schedule-effective-dated-changesSkill
- secure-a-frontend-appSkill
- security-auditSkill
- send-slackSkill
- serve-realtime-with-websocketsSkill
- structure-a-backend-serviceSkill
- structure-a-frontend-appSkill
- structure-a-shared-backend-libSkill
- structure-a-shared-ui-libSkill
- tdd-http-firstSkill
- use-feature-flagsSkill
- write-cross-cutting-codeSkill
- write-frontend-codeSkill
- write-service-codeSkill
- write-unit-testsSkill
The file
We split this skill into the rules it gives an agent
1 rule. 0 are common, 0 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 3 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 25
Prefer proving a util through the component that uses it.
“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Write frontend tests
Two layers; pick by what you're verifying. principle → ▸ Example (Jest/RTL/Cypress) → ▸ Other stacks.
| Layer | Tool | For |
| Unit / component | Jest + React Testing Library | utils, hooks, component behavior in isolation |
| E2E | Cypress + Cucumber (BDD) | real user flows through the running app |
0. Gate — does this deserve a test? (test behaviors, not files)
A suite maps to behaviors/contracts, not the file tree. Never create a test file 1:1 with a
source file by default — per-util mirror tests (foo.utils.ts → foo.utils.test.ts) bury real
failures, slow every run, and are maintained forever.
- Direct util/hook test only when the logic is genuinely complex AND matters (money, dates, parsing, non-trivial business rules) or it pins a regression that actually occurred.
- Skip it when a component/page/e2e test already exercises the behavior, or the code is trivial glue (mapping, prop plumbing, re-exports) whose breakage is instantly visible in dev.
- Prefer proving a util through the component that uses it; a separate util test duplicating
that coverage is junk. When in doubt → don't write it ("Test only what matters",
~/.claude/CLAUDE.md).
1. Unit / component (Jest + RTL)
- Colocate
*.test.ts(x)next to source (or undersrc/test/). Test behavior through the public surface: render the component, query by role/text, fire user events, assert what the user sees — not internal state. Pure utils/hooks that pass the §0 gate are tested directly. - Mock the framework + externals only:
jest.mock('next/router', () => ({ useRouter: () => ({ query: {} }) })), mock service classes; never mock the unit under test. - AAA + specific assertions (
toEqual/toMatchObjectwith real expected values, nottoBeTruthy()).
▸ Other stacks: Vitest + RTL — identical patterns.describe('convertObjectToArray', () => { it('flattens primitive values', () => { expect(convertObjectToArray({ a: 1, b: 'x' })).toEqual(['a', '1', 'b', 'x']); }); });
2. E2E (Cypress + Cucumber)
- Gherkin feature files under
cypress/e2e/<feature>/*.featuredescribe flows in Given/When/Then; step definitions implement them;Scenario Outline+Examplescover input variations. Keep API helpers incypress/services/, test data incypress/constants/, and custom commands incypress/support/.
▸ Other stacks: Playwright (+ optional BDD) — same user-flow-level coverage.Scenario: Create a listing Given User logged in When User submits the new-listing form Then The listing appears in the list
3. Gates
Lint/format = Biome (warning-first rollout, promoted to errors over time). A git-hook runner
(e.g. lefthook) runs biome check/format on staged files pre-commit, and type-check + jest
pre-push. Run pnpm test (unit) and the e2e suite before opening a PR.
Verification
- Important new behavior is covered at the outermost sensible layer (component via RTL; Cypress for a user-facing flow); any direct util/hook test passes the §0 gate — no 1:1 mirror files, no mock-only tests. Tests assert observable behavior with specific values, not truthiness.
pnpm type-check,pnpm test, and Biome all pass.
Related
structure-a-frontend-app·write-frontend-code·write-unit-tests(backend equivalent).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

