Skip to content

Commit 553aa65

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

File tree

6 files changed

+20
-27
lines changed

6 files changed

+20
-27
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: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,11 @@ 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 safe area inset variables
5957
html.style.setProperty('--safe-area-inset-top', '10px');
6058
html.style.setProperty('--safe-area-inset-bottom', '20px');
6159
html.style.setProperty('--safe-area-inset-left', '30px');
6260
html.style.setProperty('--safe-area-inset-right', '40px');
63-
html.style.setProperty('--ion-safe-area-top', 'var(--safe-area-inset-top)');
64-
html.style.setProperty('--ion-safe-area-bottom', 'var(--safe-area-inset-bottom)');
65-
html.style.setProperty('--ion-safe-area-left', 'var(--safe-area-inset-left)');
66-
html.style.setProperty('--ion-safe-area-right', 'var(--safe-area-inset-right)');
6761
});
6862

6963
const top = await page.evaluate(() =>

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
}

core/src/components/modal/test/basic/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
<script src="../../../../../scripts/testing/scripts.js"></script>
1313
<script nomodule src="../../../../../dist/ionic/ionic.js"></script>
1414
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
15+
<style>
16+
:root {
17+
--ion-safe-area-top: 20px;
18+
--ion-safe-area-bottom: 20px;
19+
--ion-safe-area-right: 20px;
20+
--ion-safe-area-left: 20px;
21+
}
22+
</style>
1523
</head>
1624

1725
<body>

core/src/components/modal/test/dark-mode/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
<script nomodule src="../../../../../dist/ionic/ionic.js"></script>
1515
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
1616
<style>
17+
:root {
18+
--ion-safe-area-top: 20px;
19+
--ion-safe-area-bottom: 20px;
20+
--ion-safe-area-right: 20px;
21+
--ion-safe-area-left: 20px;
22+
}
23+
1724
.grid {
1825
display: grid;
1926
grid-template-columns: repeat(3, minmax(250px, 1fr));

0 commit comments

Comments
 (0)