first commit
This commit is contained in:
58
docs/ui/react/react-audio-fingerprint/src/test-setup.md
Normal file
58
docs/ui/react/react-audio-fingerprint/src/test-setup.md
Normal file
@@ -0,0 +1,58 @@
|
||||
# `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/vitest` to register matchers such as
|
||||
`.toBeInTheDocument()` and `.toHaveAccessibleName()`.
|
||||
- Registers an `afterEach` that calls `cleanup()` 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:
|
||||
|
||||
```ts
|
||||
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:
|
||||
|
||||
```ts
|
||||
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/runner` for `afterEach` (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`.
|
||||
Reference in New Issue
Block a user