Skip to content

Commit 0f3483d

Browse files
committed
chore(tests): fixing tests having issues with mutation observers
1 parent a5bd1dd commit 0f3483d

File tree

4 files changed

+6
-23
lines changed

4 files changed

+6
-23
lines changed

core/scripts/testing/scripts.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,6 @@
4848
document.head.appendChild(style);
4949
}
5050

51-
/**
52-
* Zero out safe-area insets in test environments.
53-
* The default 20px --ion-safe-area-top from core.scss is for legacy
54-
* status bar simulation but doesn't represent real browser behavior.
55-
* Tests that need to verify safe-area handling should explicitly set
56-
* these values in their test HTML files.
57-
*/
58-
const safeAreaStyle = document.createElement('style');
59-
safeAreaStyle.innerHTML = `
60-
:root {
61-
--ion-safe-area-top: 0px;
62-
--ion-safe-area-bottom: 0px;
63-
--ion-safe-area-left: 0px;
64-
--ion-safe-area-right: 0px;
65-
}
66-
`;
67-
document.head.appendChild(safeAreaStyle);
68-
6951
/**
7052
* The `palette` param is used to load a specific palette
7153
* for the theme.

core/src/components/app/test/safe-area/app.e2e.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ configs({ directions: ['ltr'] }).forEach(({ config, title, screenshot }) => {
5353
// Remove the safe area class
5454
html.classList.remove('safe-area');
5555

56-
// Set the Capacitor safe area inset variables.
57-
// Also set --ion-safe-area-* directly since test environments zero these out,
58-
// which would prevent the CSS var() cascade from working.
56+
// Set the Capacitor safe area inset variables and wire up
57+
// --ion-safe-area-* to use them via var() cascade.
5958
html.style.setProperty('--safe-area-inset-top', '10px');
6059
html.style.setProperty('--safe-area-inset-bottom', '20px');
6160
html.style.setProperty('--safe-area-inset-left', '30px');

core/src/components/content/content.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ComponentInterface, EventEmitter } from '@stencil/core';
22
import { Build, Component, Element, Event, Host, Listen, Method, Prop, forceUpdate, h, readTask } from '@stencil/core';
3+
import { win } from '@utils/browser';
34
import { componentOnReady, hasLazyBuild, inheritAriaAttributes } from '@utils/helpers';
45
import type { Attributes } from '@utils/helpers';
56
import { isPlatform } from '@utils/platform';
@@ -192,7 +193,7 @@ export class Content implements ComponentInterface {
192193

193194
// Watch for dynamic header/footer changes (common in React conditional rendering)
194195
const parent = this.el.parentElement;
195-
if (parent && !this.parentMutationObserver) {
196+
if (parent && !this.parentMutationObserver && win !== undefined && 'MutationObserver' in win) {
196197
this.parentMutationObserver = new MutationObserver(() => {
197198
this.updateSiblingDetection();
198199
forceUpdate(this);

core/src/components/modal/modal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ComponentInterface, EventEmitter } from '@stencil/core';
22
import { Component, Element, Event, Host, Listen, Method, Prop, State, Watch, h, writeTask } from '@stencil/core';
3+
import { win } from '@utils/browser';
34
import { findIonContent, printIonContentErrorMsg } from '@utils/content';
45
import { CoreDelegate, attachComponent, detachComponent } from '@utils/framework-delegate';
56
import { raf, inheritAttributes, hasLazyBuild, getElementRoot } from '@utils/helpers';
@@ -941,7 +942,7 @@ export class Modal implements ComponentInterface, OverlayInterface {
941942
this.updateFooterPadding();
942943

943944
// Watch for dynamic footer additions/removals (e.g., async data loading)
944-
if (!this.footerObserver) {
945+
if (!this.footerObserver && win !== undefined && 'MutationObserver' in win) {
945946
this.footerObserver = new MutationObserver(() => this.updateFooterPadding());
946947
this.footerObserver.observe(this.el, { childList: true, subtree: true });
947948
}

0 commit comments

Comments
 (0)