From 51f455346bd7a07ddacaa393efe9cdc4626e3f3a Mon Sep 17 00:00:00 2001 From: Christian Bromann Date: Wed, 2 Oct 2024 10:04:43 -0700 Subject: [PATCH] fix(mock-doc): provide mock for resize observer --- .../hydrate-factory-closure.ts | 1 + src/mock-doc/resize-observer.ts | 21 +++++++++++++++++++ src/mock-doc/window.ts | 5 +++++ 3 files changed, 27 insertions(+) create mode 100644 src/mock-doc/resize-observer.ts diff --git a/src/compiler/output-targets/dist-hydrate-script/hydrate-factory-closure.ts b/src/compiler/output-targets/dist-hydrate-script/hydrate-factory-closure.ts index 467765395fe..c844358ed7e 100644 --- a/src/compiler/output-targets/dist-hydrate-script/hydrate-factory-closure.ts +++ b/src/compiler/output-targets/dist-hydrate-script/hydrate-factory-closure.ts @@ -63,6 +63,7 @@ export function hydrateFactory($stencilWindow, $stencilHydrateOpts, $stencilHydr var HTMLTemplateElement = $stencilWindow.HTMLTemplateElement; var HTMLTitleElement = $stencilWindow.HTMLTitleElement; var IntersectionObserver = $stencilWindow.IntersectionObserver; + var ResizeObserver = $stencilWindow.ResizeObserver; var KeyboardEvent = $stencilWindow.KeyboardEvent; var MouseEvent = $stencilWindow.MouseEvent; var Node = $stencilWindow.Node; diff --git a/src/mock-doc/resize-observer.ts b/src/mock-doc/resize-observer.ts new file mode 100644 index 00000000000..2fdadd7f16a --- /dev/null +++ b/src/mock-doc/resize-observer.ts @@ -0,0 +1,21 @@ +export class MockResizeObserver { + constructor() { + /**/ + } + + disconnect() { + /**/ + } + + observe() { + /**/ + } + + takeRecords(): any[] { + return []; + } + + unobserve() { + /**/ + } +} diff --git a/src/mock-doc/window.ts b/src/mock-doc/window.ts index 6dded0f0f2b..3c0bc5e408b 100644 --- a/src/mock-doc/window.ts +++ b/src/mock-doc/window.ts @@ -21,6 +21,7 @@ import { MockLocation } from './location'; import { MockNavigator } from './navigator'; import { MockElement, MockHTMLElement, MockNode, MockNodeList } from './node'; import { MockPerformance, resetPerformance } from './performance'; +import { MockResizeObserver } from './resize-observer'; import { MockStorage } from './storage'; const nativeClearInterval = clearInterval; @@ -311,6 +312,10 @@ export class MockWindow { return MockIntersectionObserver; } + get ResizeObserver() { + return MockResizeObserver; + } + get localStorage() { if (this.__localStorage == null) { this.__localStorage = new MockStorage();