Major update for v1 and tests
This commit is contained in:
45
src/test/setup.js
Normal file
45
src/test/setup.js
Normal file
@@ -0,0 +1,45 @@
|
||||
// Vitest setup file — runs once per test file, before any test.
|
||||
//
|
||||
// Two responsibilities:
|
||||
//
|
||||
// 1. Register @testing-library/jest-dom's custom matchers so tests
|
||||
// can use `expect(node).toBeInTheDocument()`, `toHaveTextContent()`,
|
||||
// `toHaveAttribute()`, etc. Without this import, those matchers
|
||||
// throw "expected jest-dom matcher" at assertion time.
|
||||
//
|
||||
// 2. Run RTL's `cleanup()` after every test. RTL renders into a
|
||||
// shared DOM container; without explicit cleanup, components
|
||||
// from one test stick around for the next, producing
|
||||
// false-positive "found multiple instances" errors and
|
||||
// memory-grow bugs in long suites. Vitest with `globals: true`
|
||||
// exposes `afterEach` so the import below works without
|
||||
// naming it on the import side.
|
||||
//
|
||||
// What's NOT here (intentionally)
|
||||
// ─────────────────────────────────
|
||||
// • localStorage clearing. jsdom gives each test file a fresh
|
||||
// localStorage, and our tests that touch localStorage (history
|
||||
// debug flag) explicitly set+clear their own keys per test.
|
||||
// A blanket `localStorage.clear()` in afterEach would mask
|
||||
// setup bugs in tests that depend on a clean key.
|
||||
//
|
||||
// • Konva mocking. We don't yet have tests that mount React-Konva
|
||||
// components — those will need Stage/Layer stubs and will live
|
||||
// in a follow-up batch once we know the test setup story for
|
||||
// canvas-dependent code. For pure utility and hook tests
|
||||
// covered in this initial batch, Konva isn't loaded.
|
||||
//
|
||||
// • Timer mocking globals. Individual tests that need
|
||||
// `vi.useFakeTimers()` (debounce tests for updateElement, the
|
||||
// auto-dismiss toast timer, etc.) call it themselves and pair
|
||||
// with `vi.useRealTimers()` in their own afterEach. Keeping
|
||||
// it test-local rather than global makes the timing intent
|
||||
// visible at the test site.
|
||||
|
||||
import '@testing-library/jest-dom/vitest';
|
||||
import { afterEach } from 'vitest';
|
||||
import { cleanup } from '@testing-library/react';
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
});
|
||||
Reference in New Issue
Block a user