From a5ff255a5d98135895f2469da4f9caef13dd2e1a Mon Sep 17 00:00:00 2001 From: Rainer ziller Date: Thu, 26 Nov 2015 15:56:52 +0100 Subject: [PATCH] Add QunitAssert parameter to setup functions Add QunitAssert parameter to the setup, teardown, beforeEach and afterEach functions. This facilitates the usage of for example async code in the setup. --- qunit/qunit-tests.ts | 24 ++++++++++++++++++++++++ qunit/qunit.d.ts | 12 ++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/qunit/qunit-tests.ts b/qunit/qunit-tests.ts index dd0335aedc..9a3486118f 100644 --- a/qunit/qunit-tests.ts +++ b/qunit/qunit-tests.ts @@ -170,6 +170,30 @@ QUnit.module("module A", { } }); +QUnit.module("module with async setup and teardown", { + setup: function (assert) { + var done = assert.async(); + setTimeout(function () { + // prepare something for all following tests + }); + }, + teardown: function (assert) { + // clean up after each test + } +}); + +QUnit.module("module with async setup and teardown", { + beforeEach: function (assert: QUnitAssert) { + var done = assert.async(); + setTimeout(function () { + // prepare something for all following tests + }); + }, + afterEach: function () { + // clean up after each test + } +}); + QUnit.test("a test", function (assert) { function square(x) { diff --git a/qunit/qunit.d.ts b/qunit/qunit.d.ts index fde535a688..98b513b9ae 100644 --- a/qunit/qunit.d.ts +++ b/qunit/qunit.d.ts @@ -148,23 +148,27 @@ interface URLConfigItem { interface LifecycleObject { /** * Runs before each test + * @param assert * @deprecated */ - setup?: () => void; + setup?: (assert: QUnitAssert) => void; /** * Runs after each test + * @param assert * @deprecated */ - teardown?: () => void; + teardown?: (assert: QUnitAssert) => void; /** * Runs before each test + * @param assert */ - beforeEach?: () => void; + beforeEach?: (assert: QUnitAssert) => void; /** * Runs after each test + * @param assert */ - afterEach?: () => void; + afterEach?: (assert: QUnitAssert) => void; /** * Any additional properties on the hooks object will be added to that context.