diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js index ccb3e6d9c7..b04a9d8631 100644 --- a/js/tests/unit/scrollspy.js +++ b/js/tests/unit/scrollspy.js @@ -335,8 +335,7 @@ $(function () { assert.expect(4) var testOffsetMethod = function (type) { - var deferred = $.Deferred() - var navbarHtml = + var $navbar = $( '' - var contentHtml = + ) + var $content = $( '
' + '
div 1
' + '
div 2
' + '
div 3
' + '
' + ) + $navbar.appendTo('#qunit-fixture') + $content.appendTo('#qunit-fixture') - $(navbarHtml).appendTo('#qunit-fixture') - var $content = $(contentHtml) - .appendTo('#qunit-fixture') - - if (type === 'js') $content.bootstrapScrollspy({ target: '.navbar', offset: 0, method: 'offset' }) - else if (type === 'data') $(window).trigger('load') + if (type === 'js') { + $content.bootstrapScrollspy({ target: '.navbar', offset: 0, method: 'offset' }) + } + else if (type === 'data') { + $(window).trigger('load') + } var $target = $('#div-' + type + 'm-2') var scrollspy = $content.data('bs.scrollspy') assert.ok(scrollspy._offsets[1] === $target.offset().top, 'offset method with ' + type + ' option') assert.ok(scrollspy._offsets[1] !== $target.position().top, 'position method with ' + type + ' option') - - deferred.resolve() - - return deferred.promise() + $navbar.remove() + $content.remove() } - $.when(testOffsetMethod('js')) - .then(function () { testOffsetMethod('data') }) + testOffsetMethod('js') + testOffsetMethod('data') }) QUnit.test('should allow passed in option offset method: position', function (assert) { assert.expect(4) var testOffsetMethod = function (type) { - var deferred = $.Deferred() - var navbarHtml = + var $navbar = $( '' - var contentHtml = + ) + var $content = $( '
' + '
div 1
' + '
div 2
' + '
div 3
' + '
' + ) - - $(navbarHtml).appendTo('#qunit-fixture') - var $content = $(contentHtml) - .appendTo('#qunit-fixture') + $navbar.appendTo('#qunit-fixture') + $content.appendTo('#qunit-fixture') if (type === 'js') $content.bootstrapScrollspy({ target: '.navbar', offset: 0, method: 'position' }) else if (type === 'data') $(window).trigger('load') @@ -407,14 +407,12 @@ $(function () { assert.ok(scrollspy._offsets[1] !== $target.offset().top, 'offset method with ' + type + ' option') assert.ok(scrollspy._offsets[1] === $target.position().top, 'position method with ' + type + ' option') - - deferred.resolve() - - return deferred.promise() + $navbar.remove() + $content.remove() } - $.when(testOffsetMethod('js')) - .then(function () { testOffsetMethod('data') }) + testOffsetMethod('js') + testOffsetMethod('data') }) })