From: Timo Tijhof Date: Sat, 8 Jul 2017 00:35:26 +0000 (-0700) Subject: qunit: Remove redundant conditional for sandbox teardown X-Git-Tag: 1.31.0-rc.0~2695^2 X-Git-Url: http://git.cyclocoop.org/%24self?a=commitdiff_plain;h=5a49381406d6938637289beabe4ff35d15db06c5;p=lhc%2Fweb%2Fwiklou.git qunit: Remove redundant conditional for sandbox teardown Follows-up 0a208911a257, which added support for the `executeNow` parameter to QUnit.module. To properly support nested modules, we also need to skip registering a second setup and teardown because nested modules already run the beforeEach (setup), and afterEach (teardown), of their parent modules. During setup this would needlessly create two sandboxes and override the 'sandbox' property on the same 'this' context object. During teardown it would fail because the inner module's teardown would have already torn down the sandbox. Change-Id: Ib17bbbef45b2bd0247979cf0fa8aed17800c54a0 --- diff --git a/tests/qunit/data/testrunner.js b/tests/qunit/data/testrunner.js index d7da5a05c3..f023ddde3c 100644 --- a/tests/qunit/data/testrunner.js +++ b/tests/qunit/data/testrunner.js @@ -64,6 +64,12 @@ var orgModule = QUnit.module; QUnit.module = function ( name, localEnv, executeNow ) { + if ( QUnit.config.moduleStack.length ) { + // When inside a nested module, don't add our Sinon + // setup/teardown a second time. + return orgModule.apply( this, arguments ); + } + if ( arguments.length === 2 && typeof localEnv === 'function' ) { executeNow = localEnv; localEnv = undefined; @@ -85,9 +91,7 @@ localEnv.teardown.call( this ); } - if ( this.sandbox ) { - this.sandbox.verifyAndRestore(); - } + this.sandbox.verifyAndRestore(); } }, executeNow ); };