Skip to content

Commit 6fc1fd4

Browse files
authored
fix(tests): Fixes for old Safari (#8368)
1 parent da15810 commit 6fc1fd4

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/js/utils/dom.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,8 @@ export function copyStyleSheetsToWindow(win) {
878878

879879
link.rel = 'stylesheet';
880880
link.type = styleSheet.type;
881-
link.media = styleSheet.media;
881+
// For older Safari this has to be the string; on other browsers setting the MediaList works
882+
link.media = styleSheet.media.mediaText;
882883
link.href = styleSheet.href;
883884
win.document.head.appendChild(link);
884885
}

test/unit/utils/dom.test.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/* eslint-env qunit */
22
import document from 'global/document';
3-
import window from 'global/window';
43
import sinon from 'sinon';
54
import * as Dom from '../../../src/js/utils/dom.js';
6-
import { IS_SAFARI } from '../../../src/js/utils/browser.js';
75
import TestHelpers from '../test-helpers.js';
86

97
QUnit.module('utils/dom');
@@ -689,11 +687,14 @@ QUnit.test('isSingleLeftClick() checks return values for mousedown event', funct
689687
assert.ok(Dom.isSingleLeftClick(mouseEvent), 'a touch event on simulated mobiles is a single left click');
690688
});
691689

692-
// The next test is skipped on Safari < 14, which has a broken document.styleSheets
693-
// copyStyleSheetsToWindow() is only used on browsers supporting documentPictureInPicture - Chromium 113+
694-
const skipOnOldSafari = IS_SAFARI && parseInt(window.navigator.userAgent.match(/Version\/(\d+)\./)[1], 10) < 14 ? 'skip' : 'test';
690+
QUnit.test('Dom.copyStyleSheetsToWindow() copies all style sheets to a window', function(assert) {
691+
/**
692+
* This test is checking that styles are copied by comparing strings in original stylesheets to those in
693+
* documents.styleSheets in the new (fake) window. This can be problematic on older Safari as documents.styleSheets
694+
* does not always return the original style - a shorthand property like `background: white` may be returned as
695+
* `background-color: white`.
696+
*/
695697

696-
QUnit[skipOnOldSafari]('Dom.copyStyleSheetsToWindow() copies all style sheets to a window', function(assert) {
697698
const fakeWindow = document.createElement('div');
698699
const done = assert.async();
699700

@@ -705,7 +706,7 @@ QUnit[skipOnOldSafari]('Dom.copyStyleSheetsToWindow() copies all style sheets to
705706

706707
const style1 = document.createElement('style');
707708

708-
style1.textContent = 'body { background: white; }';
709+
style1.textContent = 'body { background-color: white; }';
709710
document.head.appendChild(style1);
710711

711712
const style2 = document.createElement('style');

0 commit comments

Comments
 (0)