From b90c69cdf70ae55a7ae608b074893d140d0a96b6 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Fri, 11 Jul 2014 03:25:19 +0200 Subject: [PATCH] QUnit: Detect unfinished jQuery effects or ajax requests in teardown Based on jQuery test suite https://github.com/jquery/jquery/blob/bcca4f041/test/data/testrunner.js#L113-L125 Change-Id: I1dba146a6795887c23c806f292c6425662ea4aad --- tests/qunit/data/testrunner.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/qunit/data/testrunner.js b/tests/qunit/data/testrunner.js index 50e89da8bc..f3f884a49a 100644 --- a/tests/qunit/data/testrunner.js +++ b/tests/qunit/data/testrunner.js @@ -240,6 +240,18 @@ // As a convenience feature, automatically restore warnings if they're // still suppressed by the end of the test. restoreWarnings(); + + // Check for (and clean up, if possible) incomplete animations/requests/etc. + if ( $.timers && $.timers.length !== 0 ) { + // Test may need to use fake timers, wait for animations or + // call $.fx.stop(). + throw new Error( 'Unfinished animations: ' + $.timers.length ); + } + if ( $.active !== undefined && $.active !== 0 ) { + // Test may need to use fake XHR, wait for requests or + // call abort(). + throw new Error( 'Unfinished AJAX requests: ' + $.active ); + } } }; }; -- 2.20.1