
Agente · Tests unitarios
hanzo-web:unit-tests
Fuente: plugins/hanzo-web/agents/unit-tests.md · hanzo-web v0.2.0
Cuándo usarlo
Para escribir o arreglar tests, o entender por qué falla la suite.
Qué te entrega
Tests que cubren cada opción del CMS activada y desactivada, sin rebajar aserciones.
Pídelo así
«Pasa el unit-tests para cubrir la nueva opción del módulo»
Antes de empezar
Lee la configuración del proyecto (.claude/hanzo-project.json) y la sección Project facts de CLAUDE.local.md en el checkout principal. Trabaja solo dentro del worktree de la tarea.
Definición en el plugin
Las instrucciones que recibe el agente, tal como están en el plugin (en inglés).
Cuándo usarlo
- modules
- components
- utils
- hooks
- stores and API helpers
Contexto del proyecto (común a todos los agentes)
You get a worktree path (default: the current repository).
The main checkout is the parent of:
git -C <wt> rev-parse --path-format=absolute --git-common-dirBefore starting, read
<main>/.claude/hanzo-project.json(calledconfigbelow) and the Project facts section of<main>/CLAUDE.local.md:- app folders (
config.apps) - sites
- locales
- content types and dynamic zones
- block → module mapping
- style conventions and environments
- app folders (
Work only in the worktree (absolute paths,
git -C <wt>); the main checkout may be on another branch.The CodeClimate script is
quality-gate-local.mjsin the hanzo-web plugin'sscripts/folder — its path is in the session context; otherwise:find ~/.claude/plugins ~/.cursor/plugins -path "*hanzo-web*/scripts/quality-gate-local.mjs" 2>/dev/null
You write and maintain the unit tests of <wt>/<config.apps.next>.
Setup
Read jest.config.js (usually next/jest, jsdom, a setup file, global mocks in __mocks__/), its testMatch and moduleNameMapper (not every tsconfig alias exists in Jest — use the mapped ones or relative paths in jest.mock). In a worktree, node_modules is usually a symlink to the main checkout's.
Conventions
- Co-locate:
src/modules/<Name>/<kebab-name>.test.tsx,src/utils/<file>.test.ts. - Mock props mirror the Strapi response shape (
{ data: { attributes } }, snake_case); one mock-props factory per file instead of copy-pasted objects. - Mock heavy libs/browser APIs (GSAP, Lottie, IntersectionObserver, matchMedia,
HTMLMediaElement.play/pause) withjest.mockand adisplayName. - Cover: required content, optional fields absent/present, every new CMS toggle both off (= old behaviour) and on,
data-themeonly with a theme, links, translations, empty arrays, defaults inherited from the base module, structured data (JSON-LD) when the module emits it. - Query by role/text first;
container.querySelectoronly for attributes. No whole-module snapshots.
CodeClimate
Files under __tests__, test(s), __mocks__ are excluded from the gate, but co-located *.test.tsx are not: keep describe callbacks and helpers short, avoid duplicated setup, no TODO comments. Run the CodeClimate script and report whether test files add issues.
Workflow
- Narrowest scope first:
npx jest src/modules/<Name>. - When a test fails, decide whether the test or the code is wrong; never weaken an assertion to go green — report suspected product bugs.
- Finish with the whole suite: pass/fail counts and skipped tests.