Initial Commit
This commit is contained in:
37
packages/ui/forms/react-forms/tests/setup/polyfills.ts
Normal file
37
packages/ui/forms/react-forms/tests/setup/polyfills.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
// React-specific polyfill layer. The base webcrypto polyfill is loaded via
|
||||
// `@suaveplan/testing/polyfills` (see vitest.config.ts setupFiles). This
|
||||
// file adds the React 18+ `IS_REACT_ACT_ENVIRONMENT` global expected by
|
||||
// React DOM when assertions are made outside an `act(...)` wrapper, plus
|
||||
// a `ResizeObserver` shim used by react-hook-form's controller in some
|
||||
// happy-dom branches.
|
||||
|
||||
interface ReactActEnvWindow {
|
||||
IS_REACT_ACT_ENVIRONMENT?: boolean;
|
||||
}
|
||||
|
||||
const win = globalThis as unknown as ReactActEnvWindow;
|
||||
if (win.IS_REACT_ACT_ENVIRONMENT === undefined) {
|
||||
win.IS_REACT_ACT_ENVIRONMENT = true;
|
||||
}
|
||||
|
||||
interface MaybeResizeObserverGlobal {
|
||||
ResizeObserver?: unknown;
|
||||
}
|
||||
|
||||
class ResizeObserverPolyfill {
|
||||
public observe(): void {
|
||||
// no-op: happy-dom does not lay out elements, so observed entries
|
||||
// would always carry size 0 — the polyfill is structural only.
|
||||
}
|
||||
public unobserve(): void {
|
||||
// no-op
|
||||
}
|
||||
public disconnect(): void {
|
||||
// no-op
|
||||
}
|
||||
}
|
||||
|
||||
const maybeRO = globalThis as unknown as MaybeResizeObserverGlobal;
|
||||
if (maybeRO.ResizeObserver === undefined) {
|
||||
maybeRO.ResizeObserver = ResizeObserverPolyfill;
|
||||
}
|
||||
Reference in New Issue
Block a user