]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Skip tests if `attachShadow` is not present
authorXhmikosR <xhmikosr@gmail.com>
Fri, 27 Nov 2020 09:15:54 +0000 (11:15 +0200)
committerXhmikosR <xhmikosr@gmail.com>
Wed, 15 Sep 2021 12:44:20 +0000 (15:44 +0300)
js/tests/unit/util.js

index 656477314fd81360d559a7a0e028b29492a51b9b..5884676f9c7179c9c934babd3ea5cb62e6cfa303 100644 (file)
@@ -3,6 +3,8 @@ $(function () {
 
   window.Util = typeof bootstrap !== 'undefined' ? bootstrap.Util : Util
 
+  var supportsAttachShadow = document.documentElement.attachShadow
+
   QUnit.module('util', {
     afterEach: function () {
       $('#qunit-fixture').html('')
@@ -143,13 +145,8 @@ $(function () {
     assert.true(Util.supportsTransitionEnd())
   })
 
-  QUnit.test('Util.findShadowRoot should find the shadow DOM root', function (assert) {
-    // Only for newer browsers
-    if (!document.documentElement.attachShadow) {
-      assert.expect(0)
-      return
-    }
-
+  // Only for newer browsers
+  QUnit[supportsAttachShadow ? 'test' : 'skip']('Util.findShadowRoot should find the shadow DOM root', function (assert) {
     assert.expect(2)
     var $div = $('<div id="test"></div>').appendTo($('#qunit-fixture'))
     var shadowRoot = $div[0].attachShadow({
@@ -161,23 +158,11 @@ $(function () {
     assert.strictEqual(shadowRoot, Util.findShadowRoot(shadowRoot.firstChild))
   })
 
-  QUnit.test('Util.findShadowRoot should return null when attachShadow is not available', function (assert) {
+  QUnit[supportsAttachShadow ? 'skip' : 'test']('Util.findShadowRoot should return null when attachShadow is not available', function (assert) {
     assert.expect(1)
-
     var $div = $('<div id="test"></div>').appendTo($('#qunit-fixture'))
-    if (!document.documentElement.attachShadow) {
-      assert.strictEqual(Util.findShadowRoot($div[0]), null)
-    } else {
-      var sandbox = sinon.createSandbox()
-
-      sandbox.replace(document.documentElement, 'attachShadow', function () {
-        // to avoid empty function
-        return $div
-      })
-
-      assert.strictEqual(Util.findShadowRoot($div[0]), null)
-      sandbox.restore()
-    }
+
+    assert.strictEqual(Util.findShadowRoot($div[0]), null)
   })
 
   QUnit.test('Util.jQueryDetection should detect jQuery', function (assert) {