From 4a8b29fbf5ad912228a13c7b45470b4909472e43 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Mon, 27 Jun 2016 21:41:00 -0400 Subject: [PATCH 1/2] Port #20190 to v3 Scrollspy test: Allow for async .then() in jQuery 3; fixes #20182 Instead of doing a new assert.async(), just do a single one for the entire test and let the .then() be async as well. --- js/tests/unit/scrollspy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js index bf5fa0bff5..d50573f27a 100644 --- a/js/tests/unit/scrollspy.js +++ b/js/tests/unit/scrollspy.js @@ -258,21 +258,21 @@ $(function () { var testElementIsActiveAfterScroll = function (element, target) { var deferred = $.Deferred() var scrollHeight = Math.ceil($content.scrollTop() + $(target).position().top) - var done = assert.async() $content.one('scroll', function () { assert.ok($(element).hasClass('active'), 'target:' + target + ', element: ' + element) - done() deferred.resolve() }) $content.scrollTop(scrollHeight) return deferred.promise() } + var done = assert.async() $.when(testElementIsActiveAfterScroll('#li-100-5', '#div-100-5')) .then(function () { return testElementIsActiveAfterScroll('#li-100-4', '#div-100-4') }) .then(function () { return testElementIsActiveAfterScroll('#li-100-3', '#div-100-3') }) .then(function () { return testElementIsActiveAfterScroll('#li-100-2', '#div-100-2') }) .then(function () { return testElementIsActiveAfterScroll('#li-100-1', '#div-100-1') }) + .then(function () { done() }) }) }) From bc05ef16ecc1bac850ed4230f6daac12b104de8c Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Tue, 28 Jun 2016 13:24:28 -0700 Subject: [PATCH 2/2] Port #20198 to v3 ScrollSpy unit test: Use single done() in a then() instead of multiple done()s Fixes test flakiness on OS X Safari and Android when using jQuery 3. Fixes #20182 more Refs #20191 --- js/tests/unit/scrollspy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js index d50573f27a..be6808e2e6 100644 --- a/js/tests/unit/scrollspy.js +++ b/js/tests/unit/scrollspy.js @@ -131,13 +131,12 @@ $(function () { .appendTo('#qunit-fixture') .bootstrapScrollspy({ offset: 0, target: '.navbar' }) + var done = assert.async() var testElementIsActiveAfterScroll = function (element, target) { var deferred = $.Deferred() var scrollHeight = Math.ceil($content.scrollTop() + $(target).position().top) - var done = assert.async() $content.one('scroll', function () { assert.ok($(element).hasClass('active'), 'target:' + target + ', element' + element) - done() deferred.resolve() }) $content.scrollTop(scrollHeight) @@ -146,6 +145,7 @@ $(function () { $.when(testElementIsActiveAfterScroll('#li-1', '#div-1')) .then(function () { return testElementIsActiveAfterScroll('#li-2', '#div-2') }) + .then(function () { done() }) }) QUnit.test('should add the active class correctly when there are nested elements at 0 scroll offset', function (assert) {