skills/happy-dom-tests/SKILL.md
Generates React component render tests using happy-dom and Testing Library with the "given/should" prose format. Use when writing tests for display components, hooks, user interactions, or accessibility checks.
npx skillsauth add iulspop/aidd-skills happy-dom-testsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Act as a top-tier software engineer with serious testing skills.
Write React component tests for: $ARGUMENTS
Each test must answer these 5 questions:
HappyDomTests {
Constraints {
Use Vitest with describe, expect, and test. Test files use the .test.tsx extension.
Tests must use the "given: ..., should: ..." prose format.
Colocate test files next to the component they test.
Import render, screen, userEvent, and createRoutesStub from a shared ~/test/react-test-utils module that wraps Testing Library with app providers (i18n, form context, etc.).
Create a props factory function per component with sensible defaults. Each test overrides only what it needs.
Use createRoutesStub from React Router to provide routing context. Pass initialEntries for specific routes.
Use accessible queries as the primary locator strategy: screen.getByRole, screen.getByLabel, screen.getByText.
Use screen.queryByRole (returns null) for negative assertions — never getByRole with not.toBeInTheDocument.
Use regex with case-insensitive flag for text matching: { name: /submit/i }.
Use userEvent.setup() for user interactions — never fireEvent.
Use vi.fn() for mock callbacks. Use vi.spyOn for global mocks.
Use renderHook and act for testing custom hooks. Use vi.useFakeTimers() for timer-based hooks.
Use @faker-js/faker and cuid2 in factories for realistic test data.
Use existing infrastructure factories (*-factories.server.ts) when props come from database entities.
Wrap RouterStub in additional providers (e.g. SidebarProvider) when the component requires them.
Pass hydrationData to RouterStub when the component reads loader data.
Use test.each for parametrized tests when multiple inputs produce similar outcomes.
Assert accessibility attributes: toHaveAttribute("aria-selected", "true"), toHaveAttribute("aria-current", "page").
Assert element state: toBeDisabled(), toBeEnabled(), toHaveFocus().
Assert structure: toBeInTheDocument(), toHaveAttribute("href", "/path"), toHaveTextContent(/text/i).
Capture actual and expected values in variables before asserting with toEqual for pure logic checks.
}
Boundaries {
Pure function tests without React (.test.ts) -> use /unit-tests instead
Database or server action tests (.spec.ts) -> use /integration-tests instead
Browser-level user flow tests (.e2e.ts) -> use /e2e-tests instead
This skill is for React component and hook render tests (.test.tsx) only.
}
}
documentation
Improves text for clarity, directness, and engagement following professional writing best practices. Use when editing documentation, blog posts, product copy, or any text that needs to sound human and avoid LLM patterns.
development
Generates well-structured unit tests using Vitest with the "given/should" prose format. Use when writing tests for new code, adding coverage to existing code, or following TDD practices.
development
Tailwind CSS patterns for layouts, color schemes, responsive design, and className handling. Use when writing or reviewing component styles.
development
Converts SVG files into optimized React TypeScript components with proper accessibility attributes, currentColor fills, and consistent naming conventions. Use when adding icons or SVG assets to a React project.