2.0 KiB
test-setup — Vitest global setup
Purpose
This file is loaded by vitest.config.ts via setupFiles so every test in
the package runs against a consistent jest-dom matcher set and tears down its
React tree after each case. It is intentionally short — heavy work happens in
the runner-agnostic polyfills shipped by @suaveplan/testing/polyfills, which
this file complements with DOM-specific affordances.
Features
- Imports
@testing-library/jest-dom/vitestto register matchers such as.toBeInTheDocument()and.toHaveAccessibleName(). - Registers an
afterEachthat callscleanup()from@testing-library/react, unmounting trees between tests and avoiding cross-test DOM pollution. - No mocks, no spies, no global stubs — keeps the suite faithful to the CLAUDE.md "no mocks" rule.
Usage: Basic Example
vitest.config.ts references this file:
setupFiles: [
"@suaveplan/testing/polyfills",
"./src/test-setup.ts",
],
Usage: Advanced Example
If a future component needs an additional matcher (for example to assert custom accessibility properties), add the relevant import here so every test in the package benefits without per-file boilerplate:
import "@testing-library/jest-dom/vitest";
import { afterEach } from "@suaveplan/testing/runner";
import { cleanup } from "@testing-library/react";
// (Add additional matchers or global afterEach hooks here.)
afterEach(() => cleanup());
API Reference
- No exports; runs purely for side-effects at vitest setup time.
- Depends on
@suaveplan/testing/runnerforafterEach(rule 11 compliance).
Implementation Notes
The setup file runs once per worker, so the cleanup afterEach registration
is shared across every test file in that worker. This is the canonical
pattern documented by Testing Library and matches every sibling Suaveplan
React package's setup. The package owns no provider configuration so there is
no provider-tree wrapper to install — tests render components directly via
@testing-library/react's render / renderHook.