Skip to content

Commit d56e342

Browse files
cliffhallclaude
andcommitted
test(web): resolve the last comment-contradiction + tighten the matchMedia override (round 3)
Round-3 review of PR #1793 (test infra only): - setup.ts finding 1: the inner `value:` comment still said "happy-dom doesn't implement it", contradicting the block comment two lines up (which now correctly states happy-dom v20 DOES implement matchMedia and this is an override). Dropped the false clause; kept the part that actually justifies the `as unknown as MediaQueryList` double cast (the stub omits most of the interface). - setup.ts finding 5 (folded in rather than deferred): anchored the `matches` regex to `/prefers-reduced-motion:\s*reduce/` so the override no longer also answers `true` to `(prefers-reduced-motion: no-preference)`. - renderWithMantine.tsx nit 4: the `env="test"` rationale sat on `makeWrapper`, which also builds the `env="default"` wrappers (opposite purpose). Moved it onto `renderWithMantine`, mirroring the `env="default"` rationale on `renderWithMantineTransitions`; `makeWrapper` keeps a one-liner. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01XNdjEPKLG637X8YmhDiEk5
1 parent a60c0d1 commit d56e342

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

‎clients/web/src/test/renderWithMantine.tsx‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@ export type MantineRenderOptions = Omit<RenderOptions, "wrapper"> & {
1212
colorScheme?: MantineColorScheme;
1313
};
1414

15-
// Build a MantineProvider wrapper for the given `env` + forced color scheme.
16-
// `env="test"` makes Mantine render transitions synchronously (no internal
17-
// `setTimeout`). Without it, a `Transition`/`Modal` open/close timer can fire
18-
// after happy-dom tears down `window` at the end of the run, throwing an
19-
// uncaught `ReferenceError: window is not defined` that fails the whole run
20-
// even when every assertion passed (#1760). This is the right default for the
21-
// vast majority of tests, which don't assert on mid-transition state.
15+
// Build a MantineProvider wrapper for the given Mantine `env` + forced color
16+
// scheme. See the two render helpers below for what each `env` value is for.
2217
function makeWrapper(env: "test" | "default", colorScheme: MantineColorScheme) {
2318
return function Wrapper({ children }: { children: ReactNode }) {
2419
return (
@@ -29,6 +24,13 @@ function makeWrapper(env: "test" | "default", colorScheme: MantineColorScheme) {
2924
};
3025
}
3126

27+
// Default render helper. `env="test"` makes Mantine render transitions
28+
// synchronously (no internal `setTimeout`). Without it, a `Transition`/`Modal`
29+
// open/close timer can fire after happy-dom tears down `window` at the end of
30+
// the run, throwing an uncaught `ReferenceError: window is not defined` that
31+
// fails the whole run even when every assertion passed (#1760). This is the
32+
// right default for the vast majority of tests, which don't assert on
33+
// mid-transition state.
3234
export function renderWithMantine(
3335
ui: ReactElement,
3436
options?: MantineRenderOptions,

‎clients/web/src/test/setup.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,15 @@ Object.defineProperty(globalThis, "fetch", {
7272
Object.defineProperty(window, "matchMedia", {
7373
configurable: true,
7474
writable: true,
75-
// Partial `matchMedia` mock: happy-dom doesn't implement it, and the members
76-
// below are all the app touches. The stub omits the rest of `MediaQueryList`,
77-
// so the double cast bridges the deliberately-incomplete shape.
75+
// Partial `matchMedia` override: the members below are all the app touches.
76+
// The stub omits the rest of `MediaQueryList`, so the double cast bridges the
77+
// deliberately-incomplete shape. The `matches` regex is anchored to the
78+
// `reduce` form so the stub doesn't also answer `true` to
79+
// `(prefers-reduced-motion: no-preference)` (claiming both preferences at
80+
// once); Mantine only ever queries the `reduce` form.
7881
value: (query: string): MediaQueryList =>
7982
({
80-
matches: /prefers-reduced-motion/.test(query),
83+
matches: /prefers-reduced-motion:\s*reduce/.test(query),
8184
media: query,
8285
onchange: null,
8386
addEventListener: () => {},

0 commit comments

Comments
 (0)