Skip to content

Commit

Permalink
Skip tests if attachShadow is not present
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Sep 15, 2021
1 parent 551f37a commit d4e162f
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions js/tests/unit/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('')
Expand Down Expand Up @@ -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({
Expand All @@ -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) {
Expand Down

0 comments on commit d4e162f

Please sign in to comment.