diff --git a/test/main/assert.js b/test/main/assert.js index 013b3fe26..9398ecd30 100644 --- a/test/main/assert.js +++ b/test/main/assert.js @@ -87,7 +87,6 @@ QUnit.test( "notStrictEqual", function( assert ) { } ); QUnit.test( "propEqual", function( assert ) { - assert.expect( 5 ); var objectCreate = Object.create || function( origin ) { function O() {} O.prototype = origin; @@ -164,7 +163,6 @@ QUnit.test( "propEqual", function( assert ) { } ); QUnit.test( "throws", function( assert ) { - assert.expect( 20 ); function CustomError( message ) { this.message = message; } @@ -354,9 +352,11 @@ QUnit.test( "throws", function( assert ) { ); } ); -QUnit.test( "rejects", function( assert ) { - assert.expect( 16 ); +QUnit.test( "raises", function( assert ) { + assert.strictEqual( assert.raises, assert.throws, "alias for throws" ); +} ); +QUnit.test( "rejects", function( assert ) { function CustomError( message ) { this.message = message; } @@ -471,10 +471,6 @@ QUnit.test( "rejects", function( assert ) { ); } ); -QUnit.test( "raises, alias for throws", function( assert ) { - assert.strictEqual( assert.raises, assert.throws ); -} ); - QUnit.module( "failing assertions", { beforeEach: function( assert ) { var originalPushResult = assert.pushResult; @@ -664,21 +660,3 @@ QUnit.test( "rejects", function( assert ) { "rejects fails when provided an array" ); } ); - -( function() { - var previousTestAssert; - - QUnit.module( "delayed assertions" ); - - QUnit.test( "assertions after test finishes throws an error - part 1", function( assert ) { - assert.expect( 0 ); - previousTestAssert = assert; - } ); - - QUnit.test( "assertions after test finishes throws an error - part 2", function( assert ) { - assert.expect( 1 ); - assert.throws( function() { - previousTestAssert.ok( true ); - }, /Assertion occurred after test had finished/ ); - } ); -}() ); diff --git a/test/main/assert/step.js b/test/main/assert/step.js index bdd771448..42a97a119 100644 --- a/test/main/assert/step.js +++ b/test/main/assert/step.js @@ -1,161 +1,152 @@ -QUnit.module( "assert.step" ); +QUnit.module( "assert.step", function() { -QUnit.test( "pushes a failing assertion if no message is given", function( assert ) { - assert.expect( 3 ); + QUnit.test( "pushes a failing assertion if no message is given", function( assert ) { + var originalPushResult = assert.pushResult; + assert.pushResult = function pushResultStub( resultInfo ) { + assert.pushResult = originalPushResult; - var originalPushResult = assert.pushResult; - assert.pushResult = function pushResultStub( resultInfo ) { - assert.pushResult = originalPushResult; - - assert.false( resultInfo.result ); - assert.equal( resultInfo.message, "You must provide a message to assert.step" ); - }; - - assert.step(); - - assert.verifySteps( [ undefined ] ); -} ); - -QUnit.test( "pushes a failing assertion if empty message is given", function( assert ) { - assert.expect( 3 ); - - var originalPushResult = assert.pushResult; - assert.pushResult = function pushResultStub( resultInfo ) { - assert.pushResult = originalPushResult; - - assert.false( resultInfo.result ); - assert.equal( resultInfo.message, "You must provide a message to assert.step" ); - }; + assert.false( resultInfo.result ); + assert.equal( resultInfo.message, "You must provide a message to assert.step" ); + }; - assert.step( "" ); - - assert.verifySteps( [ "" ] ); -} ); - -QUnit.test( "pushes a failing assertion if a non string message is given", function( assert ) { - assert.expect( 7 ); + assert.step(); + assert.verifySteps( [ undefined ] ); + } ); - var count = 0; - var originalPushResult = assert.pushResult; + QUnit.test( "pushes a failing assertion if empty message is given", function( assert ) { + var originalPushResult = assert.pushResult; + assert.pushResult = function pushResultStub( resultInfo ) { + assert.pushResult = originalPushResult; - assert.pushResult = function pushResultStub( resultInfo ) { - assert.pushResult = originalPushResult; + assert.false( resultInfo.result ); + assert.equal( resultInfo.message, "You must provide a message to assert.step" ); + }; - count += 1; + assert.step( "" ); + assert.verifySteps( [ "" ] ); + } ); - assert.false( resultInfo.result ); - assert.equal( resultInfo.message, "You must provide a string value to assert.step" ); + QUnit.test( "pushes a failing assertion if a non string message is given", function( assert ) { + var count = 0; + var originalPushResult = assert.pushResult; - if ( count < 3 ) { - assert.pushResult = pushResultStub; - } - }; + assert.pushResult = function pushResultStub( resultInfo ) { + assert.pushResult = originalPushResult; - assert.step( 1 ); - assert.step( null ); - assert.step( false ); + count += 1; - assert.verifySteps( [ 1, null, false ] ); -} ); + assert.false( resultInfo.result ); + assert.equal( resultInfo.message, "You must provide a string value to assert.step" ); -QUnit.test( "pushes a passing assertion if a message is given", function( assert ) { - assert.expect( 3 ); + if ( count < 3 ) { + assert.pushResult = pushResultStub; + } + }; - assert.step( "One step" ); - assert.step( "Two step" ); + assert.step( 1 ); + assert.step( null ); + assert.step( false ); - assert.verifySteps( [ "One step", "Two step" ] ); -} ); + assert.verifySteps( [ 1, null, false ] ); + } ); -QUnit.module( "assert.verifySteps" ); + QUnit.test( "pushes a passing assertion if a message is given", function( assert ) { + assert.step( "One step" ); + assert.step( "Two step" ); -QUnit.test( "verifies the order and value of steps", function( assert ) { - assert.expect( 10 ); + assert.verifySteps( [ "One step", "Two step" ] ); + } ); - assert.step( "One step" ); - assert.step( "Two step" ); - assert.step( "Red step" ); - assert.step( "Blue step" ); + QUnit.test( "step() and verifySteps() count as assertions", function( assert ) { + assert.expect( 3 ); - assert.verifySteps( [ "One step", "Two step", "Red step", "Blue step" ] ); + assert.step( "One" ); + assert.step( "Two" ); - assert.step( "One step" ); - assert.step( "Two step" ); - assert.step( "Red step" ); - assert.step( "Blue step" ); + assert.verifySteps( [ "One", "Two" ], "Three" ); + } ); - var originalPushResult = assert.pushResult; - assert.pushResult = function pushResultStub( resultInfo ) { - assert.pushResult = originalPushResult; + QUnit.module( "assert.verifySteps" ); - assert.false( resultInfo.result ); - }; + QUnit.test( "verifies the order and value of steps", function( assert ) { + assert.step( "One step" ); + assert.step( "Two step" ); + assert.step( "Red step" ); + assert.step( "Blue step" ); - assert.verifySteps( [ "One step", "Red step", "Two step", "Blue step" ] ); -} ); + assert.verifySteps( [ "One step", "Two step", "Red step", "Blue step" ] ); -QUnit.test( "verifies the order and value of failed steps", function( assert ) { - assert.expect( 3 ); + assert.step( "One step" ); + assert.step( "Two step" ); + assert.step( "Red step" ); + assert.step( "Blue step" ); - var originalPushResult = assert.pushResult; + var originalPushResult = assert.pushResult; + assert.pushResult = function pushResultStub( resultInfo ) { + assert.pushResult = originalPushResult; - assert.step( "One step" ); + assert.false( resultInfo.result ); + }; - assert.pushResult = function noop() {}; - assert.step(); - assert.step( "" ); - assert.pushResult = originalPushResult; + assert.verifySteps( [ "One step", "Red step", "Two step", "Blue step" ] ); + } ); - assert.step( "Two step" ); + QUnit.test( "verifies the order and value of failed steps", function( assert ) { + var originalPushResult = assert.pushResult; - assert.verifySteps( [ "One step", undefined, "", "Two step" ] ); -} ); + assert.step( "One step" ); -QUnit.test( "resets the step list after verification", function( assert ) { - assert.expect( 4 ); + assert.pushResult = function noop() {}; + assert.step(); + assert.step( "" ); + assert.pushResult = originalPushResult; - assert.step( "one" ); - assert.verifySteps( [ "one" ] ); + assert.step( "Two step" ); - assert.step( "two" ); - assert.verifySteps( [ "two" ] ); -} ); + assert.verifySteps( [ "One step", undefined, "", "Two step" ] ); + } ); -QUnit.test( "errors if not called when `assert.step` is used", function( assert ) { - assert.expect( 2 ); - assert.step( "one" ); + QUnit.test( "resets the step list after verification", function( assert ) { + assert.step( "one" ); + assert.verifySteps( [ "one" ] ); - var originalPushFailure = QUnit.config.current.pushFailure; - QUnit.config.current.pushFailure = function pushFailureStub( message ) { - QUnit.config.current.pushFailure = originalPushFailure; + assert.step( "two" ); + assert.verifySteps( [ "two" ] ); + } ); - assert.equal( message, "Expected assert.verifySteps() to be called before end of test after using assert.step(). Unverified steps: one" ); - }; -} ); + QUnit.test( "errors if not called when `assert.step` is used", function( assert ) { + assert.expect( 2 ); + assert.step( "one" ); -// Testing to ensure steps array is not passed by reference: https://github.com/qunitjs/qunit/issues/1266 -QUnit.module( "assert.verifySteps value reference", function() { + var original = assert.test.pushFailure; + assert.test.pushFailure = function( message ) { + assert.test.pushFailure = original; - var loggedAssertions = {}; + assert.equal( message, "Expected assert.verifySteps() to be called before end of test after using assert.step(). Unverified steps: one" ); + }; + } ); - QUnit.log( function( details ) { + // Testing to ensure steps array is not passed by reference: https://github.com/qunitjs/qunit/issues/1266 + QUnit.module( "assert.verifySteps value reference", function() { - if ( details.message === "verification-assertion" ) { - loggedAssertions[ details.message ] = details; - } + var loggedAssertions = {}; - } ); + QUnit.log( function( details ) { + if ( details.message === "verification-assertion" ) { + loggedAssertions[ details.message ] = details; + } + } ); - QUnit.test( "passing test to see if steps array is passed by reference to logging function", function( assert ) { - assert.step( "step one" ); - assert.step( "step two" ); + QUnit.test( "passing test to see if steps array is passed by reference to logging function", function( assert ) { + assert.step( "step one" ); + assert.step( "step two" ); - assert.verifySteps( [ "step one", "step two" ], "verification-assertion" ); - } ); + assert.verifySteps( [ "step one", "step two" ], "verification-assertion" ); + } ); - QUnit.test( "steps array should not be reset in logging function", function( assert ) { - var result = loggedAssertions[ "verification-assertion" ].actual; - assert.deepEqual( result, [ "step one", "step two" ] ); + QUnit.test( "steps array should not be reset in logging function", function( assert ) { + var result = loggedAssertions[ "verification-assertion" ].actual; + assert.deepEqual( result, [ "step one", "step two" ] ); + } ); } ); - } ); diff --git a/test/main/assert/timeout.js b/test/main/assert/timeout.js index 88050941c..3f30eae6e 100644 --- a/test/main/assert/timeout.js +++ b/test/main/assert/timeout.js @@ -3,9 +3,9 @@ QUnit.module( "assert.timeout", function() { assert.timeout( 10 ); assert.expect( 1 ); - var originalPushFailure = QUnit.config.current.pushFailure; - QUnit.config.current.pushFailure = function pushFailureStub( message ) { - QUnit.config.current.pushFailure = originalPushFailure; + var original = assert.test.pushFailure; + assert.test.pushFailure = function( message ) { + assert.test.pushFailure = original; assert.equal( message, "Test took longer than 10ms; test timed out." ); }; @@ -17,9 +17,9 @@ QUnit.module( "assert.timeout", function() { assert.timeout( 10 ); assert.expect( 1 ); - var originalPushFailure = QUnit.config.current.pushFailure; - QUnit.config.current.pushFailure = function pushFailureStub( message ) { - QUnit.config.current.pushFailure = originalPushFailure; + var original = assert.test.pushFailure; + assert.test.pushFailure = function( message ) { + assert.test.pushFailure = original; assert.equal( message, "Test took longer than 10ms; test timed out." ); }; @@ -51,9 +51,9 @@ QUnit.module( "assert.timeout", function() { setTimeout( function() { assert.timeout( 10 ); - var originalPushFailure = QUnit.config.current.pushFailure; - QUnit.config.current.pushFailure = function pushFailureStub( message ) { - QUnit.config.current.pushFailure = originalPushFailure; + var original = assert.test.pushFailure; + assert.test.pushFailure = function( message ) { + assert.test.pushFailure = original; assert.equal( message, "Test took longer than 10ms; test timed out." ); done(); @@ -64,9 +64,9 @@ QUnit.module( "assert.timeout", function() { QUnit.module( "a value of zero", function() { function stubPushFailure( assert ) { - var originalPushFailure = QUnit.config.current.pushFailure; - QUnit.config.current.pushFailure = function pushFailureStub( message ) { - QUnit.config.current.pushFailure = originalPushFailure; + var original = assert.test.pushFailure; + assert.test.pushFailure = function( message ) { + assert.test.pushFailure = original; assert.equal( message, diff --git a/test/main/async.js b/test/main/async.js index 89bc3f0c4..2daefdd62 100644 --- a/test/main/async.js +++ b/test/main/async.js @@ -1,187 +1,114 @@ -function asyncCallback( assert ) { - var done = assert.async(); - setTimeout( function() { - assert.true( true ); - done(); - } ); -} +QUnit.module( "assert.async", function() { -QUnit.module( "assert.async" ); + QUnit.test( "single call synchronously", function( assert ) { + var done; -QUnit.test( "single call", function( assert ) { - var done = assert.async(); + assert.expect( 1 ); + done = assert.async(); - assert.expect( 1 ); - setTimeout( function() { assert.true( true ); done(); } ); -} ); -QUnit.test( "multiple call", function( assert ) { - var done = assert.async( 4 ); + QUnit.test( "single call", function( assert ) { + var done = assert.async(); - assert.expect( 4 ); - setTimeout( function() { - assert.true( true ); - done(); - } ); - setTimeout( function() { - assert.true( true ); - done(); - } ); - setTimeout( function() { - assert.true( true ); - done(); - } ); - setTimeout( function() { - assert.true( true ); - done(); + assert.expect( 1 ); + setTimeout( function() { + assert.true( true ); + done(); + } ); } ); -} ); - -QUnit.test( "parallel calls", function( assert ) { - var done1 = assert.async(), - done2 = assert.async(); - - assert.expect( 2 ); - setTimeout( function() { - assert.true( true ); - done1(); - } ); - setTimeout( function() { - assert.true( true ); - done2(); - } ); -} ); + QUnit.test( "multiple calls", function( assert ) { + var done = assert.async( 4 ); -QUnit.test( "parallel calls of differing speeds", function( assert ) { - var done1 = assert.async(), - done2 = assert.async(); + assert.expect( 4 ); + setTimeout( function() { + assert.true( true ); + done(); + } ); + setTimeout( function() { + assert.true( true ); + done(); + } ); + setTimeout( function() { + assert.true( true ); + done(); + } ); + setTimeout( function() { + assert.true( true ); + done(); + } ); - assert.expect( 2 ); - setTimeout( function() { - assert.true( true ); - done1(); } ); - setTimeout( function() { - assert.true( true ); - done2(); - }, 100 ); -} ); -QUnit.test( "waterfall calls", function( assert ) { - var done2, - done1 = assert.async(); + QUnit.test( "parallel calls", function( assert ) { + var done1 = assert.async(), + done2 = assert.async(); - assert.expect( 2 ); - setTimeout( function() { - assert.true( true, "first" ); - done1(); - done2 = assert.async(); + assert.expect( 2 ); setTimeout( function() { - assert.true( true, "second" ); + assert.true( true ); + done1(); + } ); + setTimeout( function() { + assert.true( true ); done2(); } ); } ); -} ); -QUnit.test( "waterfall calls of differing speeds", function( assert ) { - var done2, - done1 = assert.async(); + QUnit.test( "parallel calls of differing speeds", function( assert ) { + var done1 = assert.async(), + done2 = assert.async(); - assert.expect( 2 ); - setTimeout( function() { - assert.true( true, "first" ); - done1(); - done2 = assert.async(); + assert.expect( 2 ); setTimeout( function() { - assert.true( true, "second" ); + assert.true( true ); + done1(); + } ); + setTimeout( function() { + assert.true( true ); done2(); }, 100 ); } ); -} ); - -QUnit.test( "fails if callback is called more than once in test", function( assert ) { - - // Having an outer async flow in this test avoids the need to manually modify QUnit internals - // in order to avoid post-`done` assertions causing additional failures - var done = assert.async(); - - assert.expect( 1 ); - - // Duck-punch to force an Error to be thrown instead of a `pushFailure` call - assert.test.pushFailure = function( msg ) { - throw new Error( msg ); - }; - - var overDone = assert.async(); - overDone(); - - assert.throws( function() { - overDone(); - }, new RegExp( "Too many calls to the `assert.async` callback" ) ); - - done(); -} ); - -QUnit.test( "fails if callback is called more than callback call count", function( assert ) { - - // Having an outer async flow in this test avoids the need to manually modify QUnit internals - // in order to avoid post-`done` assertions causing additional failures - var done = assert.async(); - - assert.expect( 1 ); - // Duck-punch to force an Error to be thrown instead of a `pushFailure` call - assert.test.pushFailure = function( msg ) { - throw new Error( msg ); - }; + QUnit.test( "waterfall calls", function( assert ) { + var done2, + done1 = assert.async(); - var overDone = assert.async( 3 ); - overDone(); - overDone(); - overDone(); - - assert.throws( function() { - overDone(); - }, new RegExp( "Too many calls to the `assert.async` callback" ) ); - - done(); -} ); - -( function() { - var previousTestDone; - - QUnit.test( "errors if callback is called after test - part 1", function( assert ) { - assert.expect( 0 ); - previousTestDone = assert.async(); - previousTestDone(); - } ); - - QUnit.test( "errors if callback is called after test - part 2", function( assert ) { - assert.throws( previousTestDone, /assert.async callback called after test finished./ ); + assert.expect( 2 ); + setTimeout( function() { + assert.true( true, "first" ); + done1(); + done2 = assert.async(); + setTimeout( function() { + assert.true( true, "second" ); + done2(); + } ); + } ); } ); -}() ); -QUnit.module( "assert.async in module hooks", { - before: asyncCallback, - beforeEach: asyncCallback, - afterEach: asyncCallback, - after: asyncCallback -} ); + QUnit.test( "waterfall calls of differing speeds", function( assert ) { + var done2, + done1 = assert.async(); -QUnit.test( "calls in all hooks", function( assert ) { - assert.expect( 5 ); - asyncCallback( assert ); -} ); + assert.expect( 2 ); + setTimeout( function() { + assert.true( true, "first" ); + done1(); + done2 = assert.async(); + setTimeout( function() { + assert.true( true, "second" ); + done2(); + }, 100 ); + } ); + } ); -QUnit.module( "assert.async fails if callback is called more than once in", { - before: function( assert ) { + QUnit.test( "fails if called more than once", function( assert ) { - // Having an outer async flow in this test avoids the need to manually modify QUnit - // internals in order to avoid post-`done` assertions causing additional failures + // Having an outer async flow in this test avoids the need to manually modify QUnit internals + // in order to avoid post-`done` assertions causing additional failures var done = assert.async(); assert.expect( 1 ); @@ -199,16 +126,12 @@ QUnit.module( "assert.async fails if callback is called more than once in", { }, new RegExp( "Too many calls to the `assert.async` callback" ) ); done(); - } -} ); - -QUnit.test( "before", function() {} ); + } ); -QUnit.module( "assert.async fails if callback is called more than once in", { - beforeEach: function( assert ) { + QUnit.test( "fails if called more than specified count", function( assert ) { - // Having an outer async flow in this test avoids the need to manually modify QUnit - // internals in order to avoid post-`done` assertions causing additional failures + // Having an outer async flow in this test avoids the need to manually modify QUnit internals + // in order to avoid post-`done` assertions causing additional failures var done = assert.async(); assert.expect( 1 ); @@ -218,7 +141,9 @@ QUnit.module( "assert.async fails if callback is called more than once in", { throw new Error( msg ); }; - var overDone = assert.async(); + var overDone = assert.async( 3 ); + overDone(); + overDone(); overDone(); assert.throws( function() { @@ -226,223 +151,211 @@ QUnit.module( "assert.async fails if callback is called more than once in", { }, new RegExp( "Too many calls to the `assert.async` callback" ) ); done(); - } -} ); + } ); -QUnit.test( "beforeEach", function() { } ); + ( function() { + var previousTestDone; -QUnit.module( "assert.async fails if callback is called more than once in", { - afterEach: function( assert ) { + QUnit.test( "errors if called after test finishes - part 1", function( assert ) { + assert.expect( 0 ); + previousTestDone = assert.async(); + previousTestDone(); + } ); - // Having an outer async flow in this test avoids the need to manually modify QUnit - // internals in order to avoid post-`done` assertions causing additional failures - var done = assert.async(); + QUnit.test( "errors if called after test finishes - part 2", function( assert ) { + assert.throws( previousTestDone, /assert.async callback called after test finished./ ); + } ); + }() ); - assert.expect( 1 ); + QUnit.module( "overcalled in before hook", { + before: function( assert ) { - // Duck-punch to force an Error to be thrown instead of a `pushFailure` call - assert.test.pushFailure = function( msg ) { - throw new Error( msg ); - }; + // Having an outer async flow in this test avoids the need to manually modify QUnit + // internals in order to avoid post-`done` assertions causing additional failures + var done = assert.async(); - var overDone = assert.async(); - overDone(); + // Duck-punch to force an Error to be thrown instead of a `pushFailure` call + assert.test.pushFailure = function( msg ) { + throw new Error( msg ); + }; - assert.throws( function() { + var overDone = assert.async(); overDone(); - }, new RegExp( "Too many calls to the `assert.async` callback" ) ); - - done(); - } -} ); - -QUnit.test( "afterEach", function() { } ); -QUnit.module( "assert.async fails if callback is called more than once in", { - after: function( assert ) { + assert.throws( function() { + overDone(); + }, new RegExp( "Too many calls to the `assert.async` callback" ) ); - // Having an outer async flow in this test avoids the need to manually modify QUnit - // internals in order to avoid post-`done` assertions causing additional failures - var done = assert.async(); + done(); + } + }, function() { + QUnit.test( "test", function() {} ); + } ); - assert.expect( 1 ); + QUnit.module( "overcalled in beforeEach hook", { + beforeEach: function( assert ) { - // Duck-punch to force an Error to be thrown instead of a `pushFailure` call - assert.test.pushFailure = function( msg ) { - throw new Error( msg ); - }; + // Having an outer async flow in this test avoids the need to manually modify QUnit + // internals in order to avoid post-`done` assertions causing additional failures + var done = assert.async(); - var overDone = assert.async(); - overDone(); + // Duck-punch to force an Error to be thrown instead of a `pushFailure` call + assert.test.pushFailure = function( msg ) { + throw new Error( msg ); + }; - assert.throws( function() { + var overDone = assert.async(); overDone(); - }, new RegExp( "Too many calls to the `assert.async` callback" ) ); - done(); - } -} ); - -QUnit.test( "after", function() {} ); + assert.throws( function() { + overDone(); + }, new RegExp( "Too many calls to the `assert.async` callback" ) ); -QUnit.module( "assert.async in before", { - before: function( assert ) { - var done = assert.async(), - testContext = this; - setTimeout( function() { - testContext.state = "before"; done(); - } ); - } -} ); + } + }, function() { + QUnit.test( "test", function() {} ); + } ); -QUnit.test( "before synchronized", function( assert ) { - assert.expect( 1 ); - assert.equal( this.state, "before", "before synchronized before test callback was " + - "executed" ); -} ); + QUnit.module( "overcalled in afterEach hook", { + afterEach: function( assert ) { -QUnit.module( "assert.async in beforeEach", { - beforeEach: function( assert ) { - var done = assert.async(), - testContext = this; - setTimeout( function() { - testContext.state = "beforeEach"; - done(); - } ); - } -} ); + // Having an outer async flow in this test avoids the need to manually modify QUnit + // internals in order to avoid post-`done` assertions causing additional failures + var done = assert.async(); -QUnit.test( "beforeEach synchronized", function( assert ) { - assert.expect( 1 ); - assert.equal( this.state, "beforeEach", "beforeEach synchronized before test callback was " + - "executed" ); -} ); + // Duck-punch to force an Error to be thrown instead of a `pushFailure` call + assert.test.pushFailure = function( msg ) { + throw new Error( msg ); + }; -QUnit.module( "assert.async before afterEach", { - afterEach: function( assert ) { - assert.equal( this.state, "done", "test callback synchronized before afterEach was " + - "executed" ); - } -} ); + var overDone = assert.async(); + overDone(); -QUnit.test( "afterEach will synchronize", function( assert ) { - assert.expect( 1 ); - var done = assert.async(), - testContext = this; - setTimeout( function() { - testContext.state = "done"; - done(); - } ); -} ); + assert.throws( function() { + overDone(); + }, new RegExp( "Too many calls to the `assert.async` callback" ) ); -QUnit.module( "assert.async in afterEach", { - afterEach: function( assert ) { - var done = assert.async(); - setTimeout( function() { - assert.true( true, "afterEach synchronized before test was finished" ); done(); - } ); - } -} ); - -QUnit.test( "afterEach will synchronize", function( assert ) { - assert.expect( 1 ); -} ); - -QUnit.module( "assert.async before after", { - after: function( assert ) { - assert.equal( this.state, "done", "test callback synchronized before after was " + - "executed" ); - } -} ); - -QUnit.test( "after will synchronize", function( assert ) { - assert.expect( 1 ); - var done = assert.async(), - testContext = this; - setTimeout( function() { - testContext.state = "done"; - done(); + } + }, function() { + QUnit.test( "test", function() {} ); } ); -} ); -QUnit.module( "assert.async in after", { - after: function( assert ) { - var done = assert.async(); - setTimeout( function() { - assert.true( true, "after synchronized before test was finished" ); - done(); - } ); - } -} ); + QUnit.module( "overcalled in after hook", { + after: function( assert ) { -QUnit.test( "after will synchronize", function( assert ) { - assert.expect( 1 ); -} ); + // Having an outer async flow in this test avoids the need to manually modify QUnit + // internals in order to avoid post-`done` assertions causing additional failures + var done = assert.async(); -QUnit.module( "assert.async callback event loop timing" ); + // Duck-punch to force an Error to be thrown instead of a `pushFailure` call + assert.test.pushFailure = function( msg ) { + throw new Error( msg ); + }; -QUnit.test( "`done` can be called synchronously", function( assert ) { - var done; + var overDone = assert.async(); + overDone(); - assert.expect( 1 ); - done = assert.async(); + assert.throws( function() { + overDone(); + }, new RegExp( "Too many calls to the `assert.async` callback" ) ); - assert.true( true ); - done(); -} ); + done(); + } + }, function() { + QUnit.test( "test", function() {} ); + } ); -QUnit.test( "sole `done` is called last", function( assert ) { - var done; + QUnit.module( "in before hook", { + before: function( assert ) { + var done = assert.async(), + testContext = this; + setTimeout( function() { + testContext.state = "before"; + done(); + } ); + } + }, function() { + QUnit.test( "call order", function( assert ) { + assert.equal( this.state, "before", "called before test callback" ); + } ); + } ); - assert.expect( 1 ); - done = assert.async(); - setTimeout( function() { - assert.true( true, "should pass if called before `done`" ); - done(); + QUnit.module( "in beforeEach hook", { + beforeEach: function( assert ) { + var done = assert.async(), + testContext = this; + setTimeout( function() { + testContext.state = "beforeEach"; + done(); + } ); + } + }, function() { + QUnit.test( "call order", function( assert ) { + assert.equal( this.state, "beforeEach", "called before test callback" ); + } ); } ); -} ); -QUnit.test( "multiple `done` calls, no assertions after final `done`", function( assert ) { - var done1, done2; + QUnit.module( "in afterEach hook", { + afterEach: function( assert ) { + assert.equal( this.state, "done", "called after test callback" ); + assert.true( true, "called before expected assert count is validated" ); + } + }, function() { + QUnit.test( "call order", function( assert ) { + assert.expect( 2 ); + var done = assert.async(), + testContext = this; + setTimeout( function() { + testContext.state = "done"; + done(); + } ); + } ); + } ); - assert.expect( 2 ); - done1 = assert.async(); - done2 = assert.async(); - setTimeout( function() { - done1(); - assert.true( true, "should pass if called after this `done` but before final `done`" ); + QUnit.module( "in after hook", { + after: function( assert ) { + assert.equal( this.state, "done", "called after test callback" ); + assert.true( true, "called before expected assert count is validated" ); + } + }, function() { + QUnit.test( "call order", function( assert ) { + assert.expect( 2 ); + var done = assert.async(), + testContext = this; + setTimeout( function() { + testContext.state = "done"; + done(); + } ); + } ); } ); - setTimeout( function() { - assert.true( true, "should pass if called before final `done`" ); - done2(); + + QUnit.module( "assertions after final assert.async callback", { + before: function( assert ) { + assert.async()(); + assert.true( true, "before" ); + }, + + beforeEach: function( assert ) { + assert.async()(); + assert.true( true, "beforeEach" ); + }, + + afterEach: function( assert ) { + assert.async()(); + assert.true( true, "afterEach" ); + }, + + after: function( assert ) { + assert.async()(); + assert.true( true, "after" ); + } } ); -} ); -QUnit.module( "assertions after final assert.async callback", { - before: function( assert ) { - assert.async()(); - assert.true( true, "before" ); - }, - - beforeEach: function( assert ) { - assert.async()(); - assert.true( true, "beforeEach" ); - }, - - afterEach: function( assert ) { - assert.async()(); - assert.true( true, "afterEach" ); - }, - - after: function( assert ) { - assert.async()(); - assert.true( true, "after" ); - } -} ); + QUnit.test( "in any hook still pass", function( assert ) { + assert.expect( 5 ); + assert.true( true, "test callback" ); + } ); -QUnit.test( "in any hook still pass", function( assert ) { - assert.expect( 5 ); - assert.true( true, "test callback" ); } ); diff --git a/test/main/deepEqual.js b/test/main/deepEqual.js index e5570ffa1..522fe1245 100644 --- a/test/main/deepEqual.js +++ b/test/main/deepEqual.js @@ -1689,9 +1689,7 @@ QUnit.test( "Test that must be done at the end because they extend some primitiv } ); -QUnit.module( "equiv Object-wrapped primitives" ); - -QUnit.test( "Number", function( assert ) { +QUnit.test( "Number objects", function( assert ) { var SafeNumber = Number; assert.true( QUnit.equiv( new SafeNumber( 1 ), new SafeNumber( 1 ) ), @@ -1715,7 +1713,7 @@ QUnit.test( "Number", function( assert ) { ); } ); -QUnit.test( "String", function( assert ) { +QUnit.test( "String objects", function( assert ) { var SafeString = String; assert.true( QUnit.equiv( new SafeString( "foo" ), new SafeString( "foo" ) ), @@ -1733,7 +1731,7 @@ QUnit.test( "String", function( assert ) { ); } ); -QUnit.test( "Boolean", function( assert ) { +QUnit.test( "Boolean objects", function( assert ) { var SafeBoolean = Boolean; assert.true( QUnit.equiv( new SafeBoolean( true ), new SafeBoolean( true ) ), @@ -1748,8 +1746,6 @@ QUnit.test( "Boolean", function( assert ) { ); } ); -QUnit.module( "equiv Maps and Sets" ); - var hasES6Set = ( function() { if ( typeof Set !== "function" ) { return false; @@ -1966,13 +1962,11 @@ QUnit[ hasES6Map ? "test" : "skip" ]( "Maps", function( assert ) { assert.equal( QUnit.equiv( m1, m2 ), false, "Maps containing different sets" ); } ); -QUnit.module( "equiv Symbols" ); - var hasES6Symbol = ( function() { return typeof Symbol === "function"; }() ); -QUnit[ hasES6Symbol ? "test" : "skip" ]( "regular checks", function( assert ) { +QUnit[ hasES6Symbol ? "test" : "skip" ]( "Symbols", function( assert ) { var a = Symbol( 1 ); var b = Symbol( 1 ); diff --git a/test/main/dump.js b/test/main/dump.js index d47030cda..acb6beae0 100644 --- a/test/main/dump.js +++ b/test/main/dump.js @@ -35,7 +35,6 @@ QUnit.test( "dump output, shallow", function( assert ) { }, left: 0 }; - assert.expect( 4 ); QUnit.dump.maxDepth = 1; assert.equal( QUnit.dump.parse( obj ), "{\n \"left\": 0,\n \"top\": [object Object]\n}" ); @@ -202,49 +201,46 @@ QUnit.test( "Custom parser", function( assert ) { assert.equal( QUnit.dump.parsers.CustomObject, parser ); } ); -QUnit.module( "dump, recursions", { - Wrap: function( x ) { - this.wrap = x; - if ( x === undefined ) { - this.first = true; - } - }, - chainwrap: function( depth, first, prev ) { - depth = depth || 0; - var last = prev || new this.Wrap(); - first = first || last; - - if ( depth === 1 ) { - first.wrap = last; - } - if ( depth > 1 ) { - last = this.chainwrap( depth - 1, first, new this.Wrap( last ) ); - } +function WrapFn( x ) { + this.wrap = x; + if ( x === undefined ) { + this.first = true; + } +} + +function chainwrap( depth, first, prev ) { + depth = depth || 0; + var last = prev || new WrapFn(); + first = first || last; - return last; + if ( depth === 1 ) { + first.wrap = last; + } + if ( depth > 1 ) { + last = chainwrap( depth - 1, first, new WrapFn( last ) ); } -} ); -QUnit.test( "Check dump recursion", function( assert ) { - assert.expect( 4 ); + return last; +} +QUnit.test( "Check dump recursion", function( assert ) { var noref, nodump, selfref, selfdump, parentref, parentdump, circref, circdump; - noref = this.chainwrap( 0 ); + noref = chainwrap( 0 ); nodump = QUnit.dump.parse( noref ); assert.equal( nodump, "{\n \"first\": true,\n \"wrap\": undefined\n}" ); - selfref = this.chainwrap( 1 ); + selfref = chainwrap( 1 ); selfdump = QUnit.dump.parse( selfref ); assert.equal( selfdump, "{\n \"first\": true,\n \"wrap\": recursion(-1)\n}" ); - parentref = this.chainwrap( 2 ); + parentref = chainwrap( 2 ); parentdump = QUnit.dump.parse( parentref ); assert.equal( parentdump, "{\n \"wrap\": {\n \"first\": true,\n \"wrap\": recursion(-2)\n }\n}" ); - circref = this.chainwrap( 10 ); + circref = chainwrap( 10 ); circdump = QUnit.dump.parse( circref ); assert.true( new RegExp( "recursion\\(-10\\)" ).test( circdump ), "(" + circdump + ") should show -10 recursion level" @@ -254,15 +250,15 @@ QUnit.test( "Check dump recursion", function( assert ) { QUnit.test( "Check equal/deepEqual recursion", function( assert ) { var noRecursion, selfref, circref; - noRecursion = this.chainwrap( 0 ); + noRecursion = chainwrap( 0 ); assert.equal( noRecursion, noRecursion, "I should be equal to me." ); assert.deepEqual( noRecursion, noRecursion, "... and so in depth." ); - selfref = this.chainwrap( 1 ); + selfref = chainwrap( 1 ); assert.equal( selfref, selfref, "Even so if I nest myself." ); assert.deepEqual( selfref, selfref, "... into the depth." ); - circref = this.chainwrap( 10 ); + circref = chainwrap( 10 ); assert.equal( circref, circref, "Or hide that through some levels of indirection." ); assert.deepEqual( circref, circref, "... and checked on all levels!" ); } ); diff --git a/test/main/modules.js b/test/main/modules.js index 33fe068c6..c123c05d7 100644 --- a/test/main/modules.js +++ b/test/main/modules.js @@ -1,421 +1,422 @@ -QUnit.module( "before/beforeEach/afterEach/after", { - before: function() { - this.lastHook = "module-before"; - }, - beforeEach: function( assert ) { - assert.strictEqual( this.lastHook, "module-before", - "Module's beforeEach runs after before" ); - this.lastHook = "module-beforeEach"; - }, - afterEach: function( assert ) { - assert.strictEqual( this.lastHook, "test-block", - "Module's afterEach runs after current test block" ); - this.lastHook = "module-afterEach"; - }, - after: function( assert ) { - assert.strictEqual( this.lastHook, "module-afterEach", - "Module's afterEach runs before after" ); - this.lastHook = "module-after"; - } -} ); - -QUnit.test( "hooks order", function( assert ) { - assert.expect( 4 ); - - assert.strictEqual( this.lastHook, "module-beforeEach", - "Module's beforeEach runs before current test block" ); - this.lastHook = "test-block"; -} ); - -QUnit.module( "before", { - before: function( assert ) { - assert.true( true, "before hook ran" ); +QUnit.module( "QUnit.module", function() { - if ( typeof this.beforeCount === "undefined" ) { - this.beforeCount = 0; + QUnit.module( "before/beforeEach/afterEach/after", { + before: function() { + this.lastHook = "module-before"; + }, + beforeEach: function( assert ) { + assert.strictEqual( this.lastHook, "module-before", + "Module's beforeEach runs after before" ); + this.lastHook = "module-beforeEach"; + }, + afterEach: function( assert ) { + assert.strictEqual( this.lastHook, "test-block", + "Module's afterEach runs after current test block" ); + this.lastHook = "module-afterEach"; + }, + after: function( assert ) { + assert.strictEqual( this.lastHook, "module-afterEach", + "Module's afterEach runs before after" ); + this.lastHook = "module-after"; } + } ); - this.beforeCount++; - } -} ); + QUnit.test( "hooks order", function( assert ) { + assert.expect( 4 ); -QUnit.test( "runs before first test", function( assert ) { - assert.expect( 2 ); - assert.equal( this.beforeCount, 1, "beforeCount should be one" ); -} ); + assert.strictEqual( this.lastHook, "module-beforeEach", + "Module's beforeEach runs before current test block" ); + this.lastHook = "test-block"; + } ); -QUnit.test( "does not run before subsequent tests", function( assert ) { - assert.expect( 1 ); - assert.equal( this.beforeCount, 1, "beforeCount did not increase from last test" ); -} ); + QUnit.module( "before", { + before: function( assert ) { + assert.true( true, "before hook ran" ); -QUnit.module( "before (skip)", { - before: function( assert ) { - assert.true( true, "before hook ran" ); - } -} ); + if ( typeof this.beforeCount === "undefined" ) { + this.beforeCount = 0; + } -QUnit.skip( "first test in module is skipped" ); + this.beforeCount++; + } + } ); -QUnit.test( "runs before first unskipped test", function( assert ) { - assert.expect( 1 ); -} ); + QUnit.test( "runs before first test", function( assert ) { + assert.expect( 2 ); + assert.equal( this.beforeCount, 1, "beforeCount should be one" ); + } ); -QUnit.module( "after", { - after: function( assert ) { - assert.true( true, "after hook ran" ); - } -} ); + QUnit.test( "does not run before subsequent tests", function( assert ) { + assert.expect( 1 ); + assert.equal( this.beforeCount, 1, "beforeCount did not increase from last test" ); + } ); -QUnit.test( "does not run after initial tests", function( assert ) { - assert.expect( 0 ); -} ); + QUnit.module( "before (skip)", { + before: function( assert ) { + assert.true( true, "before hook ran" ); + } + } ); -QUnit.test( "runs after final test", function( assert ) { - assert.expect( 1 ); -} ); + QUnit.skip( "first test in module is skipped" ); -QUnit.module( "after (skip)", { - after: function( assert ) { - assert.true( true, "after hook ran" ); - } -} ); + QUnit.test( "runs before first unskipped test", function( assert ) { + assert.expect( 1 ); + } ); -QUnit.test( "does not run after initial tests", function( assert ) { - assert.expect( 0 ); -} ); + QUnit.module( "after", { + after: function( assert ) { + assert.true( true, "after hook ran" ); + } + } ); -QUnit.test( "runs after final unskipped test", function( assert ) { - assert.expect( 1 ); -} ); + QUnit.test( "does not run after initial tests", function( assert ) { + assert.expect( 0 ); + } ); -QUnit.skip( "last test in module is skipped" ); + QUnit.test( "runs after final test", function( assert ) { + assert.expect( 1 ); + } ); -QUnit.module( "before/after with all tests skipped", { - before: function( assert ) { - assert.true( false, "should not occur" ); - }, - after: function( assert ) { - assert.true( false, "should not occur" ); - } -} ); + QUnit.module( "after (skip)", { + after: function( assert ) { + assert.true( true, "after hook ran" ); + } + } ); -QUnit.skip( "verifier" ); + QUnit.test( "does not run after initial tests", function( assert ) { + assert.expect( 0 ); + } ); -QUnit.module( "Test context object", { - beforeEach: function( assert ) { - var key, - keys = []; + QUnit.test( "runs after final unskipped test", function( assert ) { + assert.expect( 1 ); + } ); - for ( key in this ) { - keys.push( key ); + QUnit.skip( "last test in module is skipped" ); + + QUnit.module( "before/after with all tests skipped", { + before: function( assert ) { + assert.true( false, "should not occur" ); + }, + after: function( assert ) { + assert.true( false, "should not occur" ); } - assert.deepEqual( keys, [ "helper" ] ); - }, - afterEach: function() {}, - helper: function() {} -} ); + } ); -QUnit.test( "keys", function( assert ) { - assert.expect( 1 ); - this.contextTest = true; -} ); + QUnit.skip( "verifier" ); -QUnit.module( "afterEach and assert.async", { - beforeEach: function() { - this.state = false; - }, - afterEach: function( assert ) { - assert.strictEqual( this.state, true, "Test afterEach." ); - } -} ); + QUnit.module( "Test context object", { + beforeEach: function( assert ) { + var key, + keys = []; -QUnit.test( "afterEach must be called after test ended", function( assert ) { - var testContext = this; - var done = assert.async(); - assert.expect( 1 ); - setTimeout( function() { - testContext.state = true; - done(); + for ( key in this ) { + keys.push( key ); + } + assert.deepEqual( keys, [ "helper" ] ); + }, + afterEach: function() {}, + helper: function() {} } ); -} ); -QUnit.module( "async beforeEach test", { - beforeEach: function( assert ) { - var done = assert.async(); - setTimeout( function() { - assert.true( true ); - done(); - } ); - } -} ); + QUnit.test( "keys", function( assert ) { + assert.expect( 1 ); + this.contextTest = true; + } ); -QUnit.test( "module with async beforeEach", function( assert ) { - assert.expect( 2 ); - assert.true( true ); -} ); + QUnit.module( "afterEach and assert.async", { + beforeEach: function() { + this.state = false; + }, + afterEach: function( assert ) { + assert.strictEqual( this.state, true, "Test afterEach." ); + } + } ); -QUnit.module( "async afterEach test", { - afterEach: function( assert ) { + QUnit.test( "afterEach must be called after test ended", function( assert ) { + var testContext = this; var done = assert.async(); + assert.expect( 1 ); setTimeout( function() { - assert.true( true ); + testContext.state = true; done(); } ); - } -} ); + } ); -QUnit.test( "module with async afterEach", function( assert ) { - assert.expect( 2 ); - assert.true( true ); -} ); + QUnit.module( "async beforeEach test", { + beforeEach: function( assert ) { + var done = assert.async(); + setTimeout( function() { + assert.true( true ); + done(); + } ); + } + } ); -QUnit.module( "save scope", { - foo: "foo", - beforeEach: function( assert ) { - assert.deepEqual( this.foo, "foo" ); - this.foo = "bar"; - }, - afterEach: function( assert ) { - assert.deepEqual( this.foo, "foobar" ); - } -} ); + QUnit.test( "module with async beforeEach", function( assert ) { + assert.expect( 2 ); + assert.true( true ); + } ); -QUnit.test( "scope check", function( assert ) { - assert.expect( 3 ); - assert.deepEqual( this.foo, "bar" ); - this.foo = "foobar"; -} ); + QUnit.module( "async afterEach test", { + afterEach: function( assert ) { + var done = assert.async(); + setTimeout( function() { + assert.true( true ); + done(); + } ); + } + } ); -QUnit.module( "pre-nested modules" ); + QUnit.test( "module with async afterEach", function( assert ) { + assert.expect( 2 ); + assert.true( true ); + } ); -QUnit.module( "nested modules", function() { - QUnit.module( "first outer", { - afterEach: function( assert ) { - assert.true( true, "first outer module afterEach called" ); - }, + QUnit.module( "save scope", { + foo: "foo", beforeEach: function( assert ) { - assert.true( true, "first outer beforeEach called" ); + assert.deepEqual( this.foo, "foo" ); + this.foo = "bar"; + }, + afterEach: function( assert ) { + assert.deepEqual( this.foo, "foobar" ); } - }, function() { - QUnit.module( "first inner", { + } ); + + QUnit.test( "scope check", function( assert ) { + assert.expect( 3 ); + assert.deepEqual( this.foo, "bar" ); + this.foo = "foobar"; + } ); + + QUnit.module( "nested modules", function() { + QUnit.module( "first outer", { afterEach: function( assert ) { - assert.true( true, "first inner module afterEach called" ); + assert.true( true, "first outer module afterEach called" ); }, beforeEach: function( assert ) { - assert.true( true, "first inner module beforeEach called" ); + assert.true( true, "first outer beforeEach called" ); } }, function() { - QUnit.test( "in module, before-/afterEach called in out-in-out order", function( assert ) { + QUnit.module( "first inner", { + afterEach: function( assert ) { + assert.true( true, "first inner module afterEach called" ); + }, + beforeEach: function( assert ) { + assert.true( true, "first inner module beforeEach called" ); + } + }, function() { + QUnit.test( "in module, before-/afterEach called in out-in-out order", function( assert ) { + var module = assert.test.module; + assert.equal( module.name, + "QUnit.module > nested modules > first outer > first inner" ); + assert.expect( 5 ); + } ); + } ); + + QUnit.test( "test after nested module is processed", function( assert ) { var module = assert.test.module; - assert.equal( module.name, - "nested modules > first outer > first inner" ); - assert.expect( 5 ); + assert.equal( module.name, "QUnit.module > nested modules > first outer" ); + assert.expect( 3 ); } ); - } ); - QUnit.test( "test after nested module is processed", function( assert ) { - var module = assert.test.module; - assert.equal( module.name, "nested modules > first outer" ); - assert.expect( 3 ); + QUnit.module( "second inner" ); + + QUnit.test( "test after non-nesting module declared", function( assert ) { + var module = assert.test.module; + assert.equal( module.name, "QUnit.module > nested modules > first outer > second inner" ); + assert.expect( 3 ); + } ); } ); - QUnit.module( "second inner" ); + QUnit.module( "second outer" ); - QUnit.test( "test after non-nesting module declared", function( assert ) { + QUnit.test( "test after all nesting modules processed and new module declared", function( assert ) { var module = assert.test.module; - assert.equal( module.name, "nested modules > first outer > second inner" ); - assert.expect( 3 ); + assert.equal( module.name, "QUnit.module > nested modules > second outer" ); } ); } ); - QUnit.module( "second outer" ); - - QUnit.test( "test after all nesting modules processed and new module declared", function( assert ) { - var module = assert.test.module; - assert.equal( module.name, "nested modules > second outer" ); + QUnit.test( "modules with nested functions does not spread beyond", function( assert ) { + assert.equal( assert.test.module.name, "QUnit.module" ); } ); -} ); - -QUnit.test( "modules with nested functions does not spread beyond", function( assert ) { - assert.equal( assert.test.module.name, "pre-nested modules" ); -} ); - -QUnit.module( "contained suite arguments", function( hooks ) { - QUnit.test( "hook functions", function( assert ) { - assert.strictEqual( typeof hooks.beforeEach, "function" ); - assert.strictEqual( typeof hooks.afterEach, "function" ); - } ); - - QUnit.module( "outer hooks", function( hooks ) { - var beforeEach = hooks.beforeEach; - var afterEach = hooks.afterEach; - - beforeEach( function( assert ) { - assert.true( true, "beforeEach called" ); - } ); - - afterEach( function( assert ) { - assert.true( true, "afterEach called" ); - } ); - QUnit.test( "call hooks", function( assert ) { - assert.expect( 2 ); + QUnit.module( "contained suite arguments", function( hooks ) { + QUnit.test( "hook functions", function( assert ) { + assert.strictEqual( typeof hooks.beforeEach, "function" ); + assert.strictEqual( typeof hooks.afterEach, "function" ); } ); - QUnit.module( "stacked inner hooks", function( hooks ) { + QUnit.module( "outer hooks", function( hooks ) { var beforeEach = hooks.beforeEach; var afterEach = hooks.afterEach; beforeEach( function( assert ) { - assert.true( true, "nested beforeEach called" ); + assert.true( true, "beforeEach called" ); } ); afterEach( function( assert ) { - assert.true( true, "nested afterEach called" ); + assert.true( true, "afterEach called" ); } ); QUnit.test( "call hooks", function( assert ) { - assert.expect( 4 ); + assert.expect( 2 ); } ); - } ); - } ); -} ); -QUnit.module( "contained suite `this`", function( hooks ) { - this.outer = 1; + QUnit.module( "stacked inner hooks", function( hooks ) { + var beforeEach = hooks.beforeEach; + var afterEach = hooks.afterEach; - hooks.beforeEach( function() { - this.outer++; - } ); + beforeEach( function( assert ) { + assert.true( true, "nested beforeEach called" ); + } ); - hooks.afterEach( function( assert ) { - assert.equal( - this.outer, 42, - "in-test environment modifications are visible by afterEach callbacks" - ); - } ); + afterEach( function( assert ) { + assert.true( true, "nested afterEach called" ); + } ); - QUnit.test( "`this` is shared from modules to the tests", function( assert ) { - assert.equal( this.outer, 2 ); - this.outer = 42; - } ); - - QUnit.test( "sibling tests don't share environments", function( assert ) { - assert.equal( this.outer, 2 ); - this.outer = 42; + QUnit.test( "call hooks", function( assert ) { + assert.expect( 4 ); + } ); + } ); + } ); } ); - QUnit.module( "nested suite `this`", function( hooks ) { - this.inner = true; + QUnit.module( "contained suite `this`", function( hooks ) { + this.outer = 1; - hooks.beforeEach( function( assert ) { - assert.strictEqual( this.outer, 2 ); - assert.true( this.inner ); + hooks.beforeEach( function() { + this.outer++; } ); hooks.afterEach( function( assert ) { - assert.strictEqual( this.outer, 2 ); - assert.true( this.inner ); + assert.equal( + this.outer, 42, + "in-test environment modifications are visible by afterEach callbacks" + ); + } ); - // This change affects the outermodule afterEach assertion. + QUnit.test( "`this` is shared from modules to the tests", function( assert ) { + assert.equal( this.outer, 2 ); this.outer = 42; } ); - QUnit.test( "inner modules share outer environments", function( assert ) { - assert.strictEqual( this.outer, 2 ); - assert.true( this.inner ); + QUnit.test( "sibling tests don't share environments", function( assert ) { + assert.equal( this.outer, 2 ); + this.outer = 42; } ); - } ); - QUnit.test( "tests can't see environments from nested modules", function( assert ) { - assert.strictEqual( this.inner, undefined ); - this.outer = 42; - } ); -} ); + QUnit.module( "nested suite `this`", function( hooks ) { + this.inner = true; -QUnit.module( "nested modules before/after", { - before: function( assert ) { - assert.true( true, "before hook ran" ); - this.lastHook = "before"; - }, - after: function( assert ) { - assert.strictEqual( this.lastHook, "outer-after" ); - } -}, function() { - QUnit.test( "should run before", function( assert ) { - assert.expect( 2 ); - assert.strictEqual( this.lastHook, "before" ); + hooks.beforeEach( function( assert ) { + assert.strictEqual( this.outer, 2 ); + assert.true( this.inner ); + } ); + + hooks.afterEach( function( assert ) { + assert.strictEqual( this.outer, 2 ); + assert.true( this.inner ); + + // This change affects the outermodule afterEach assertion. + this.outer = 42; + } ); + + QUnit.test( "inner modules share outer environments", function( assert ) { + assert.strictEqual( this.outer, 2 ); + assert.true( this.inner ); + } ); + } ); + + QUnit.test( "tests can't see environments from nested modules", function( assert ) { + assert.strictEqual( this.inner, undefined ); + this.outer = 42; + } ); } ); - QUnit.module( "outer", { + QUnit.module( "nested modules before/after", { before: function( assert ) { - assert.true( true, "outer before hook ran" ); - this.lastHook = "outer-before"; + assert.true( true, "before hook ran" ); + this.lastHook = "before"; }, after: function( assert ) { - assert.strictEqual( this.lastHook, "outer-test" ); - this.lastHook = "outer-after"; + assert.strictEqual( this.lastHook, "outer-after" ); } }, function() { - QUnit.module( "inner", { + QUnit.test( "should run before", function( assert ) { + assert.expect( 2 ); + assert.strictEqual( this.lastHook, "before" ); + } ); + + QUnit.module( "outer", { before: function( assert ) { - assert.strictEqual( this.lastHook, "outer-before" ); - this.lastHook = "inner-before"; + assert.true( true, "outer before hook ran" ); + this.lastHook = "outer-before"; }, after: function( assert ) { - assert.strictEqual( this.lastHook, "inner-test" ); + assert.strictEqual( this.lastHook, "outer-test" ); + this.lastHook = "outer-after"; } }, function() { - QUnit.test( "should run outer-before and inner-before", function( assert ) { - assert.expect( 3 ); - assert.strictEqual( this.lastHook, "inner-before" ); + QUnit.module( "inner", { + before: function( assert ) { + assert.strictEqual( this.lastHook, "outer-before" ); + this.lastHook = "inner-before"; + }, + after: function( assert ) { + assert.strictEqual( this.lastHook, "inner-test" ); + } + }, function() { + QUnit.test( "should run outer-before and inner-before", function( assert ) { + assert.expect( 3 ); + assert.strictEqual( this.lastHook, "inner-before" ); + } ); + + QUnit.test( "should run inner-after", function( assert ) { + assert.expect( 1 ); + this.lastHook = "inner-test"; + } ); } ); - QUnit.test( "should run inner-after", function( assert ) { - assert.expect( 1 ); - this.lastHook = "inner-test"; + QUnit.test( "should run outer-after and after", function( assert ) { + assert.expect( 2 ); + this.lastHook = "outer-test"; } ); } ); - - QUnit.test( "should run outer-after and after", function( assert ) { - assert.expect( 2 ); - this.lastHook = "outer-test"; - } ); } ); -} ); -QUnit.module( "modules with multiple hooks", function( hooks ) { - hooks.before( function( assert ) { assert.step( "before1" ); } ); - hooks.before( function( assert ) { assert.step( "before2" ); } ); + QUnit.module( "multiple hooks", function( hooks ) { + hooks.before( function( assert ) { assert.step( "before1" ); } ); + hooks.before( function( assert ) { assert.step( "before2" ); } ); - hooks.beforeEach( function( assert ) { assert.step( "beforeEach1" ); } ); - hooks.beforeEach( function( assert ) { assert.step( "beforeEach2" ); } ); + hooks.beforeEach( function( assert ) { assert.step( "beforeEach1" ); } ); + hooks.beforeEach( function( assert ) { assert.step( "beforeEach2" ); } ); - hooks.afterEach( function( assert ) { assert.step( "afterEach1" ); } ); - hooks.afterEach( function( assert ) { assert.step( "afterEach2" ); } ); + hooks.afterEach( function( assert ) { assert.step( "afterEach1" ); } ); + hooks.afterEach( function( assert ) { assert.step( "afterEach2" ); } ); - hooks.after( function( assert ) { - assert.verifySteps( [ + hooks.after( function( assert ) { + assert.verifySteps( [ - // before/beforeEach execute in FIFO order - "before1", - "before2", - "beforeEach1", - "beforeEach2", + // before/beforeEach execute in FIFO order + "before1", + "before2", + "beforeEach1", + "beforeEach2", - // after/afterEach execute in LIFO order - "afterEach2", - "afterEach1", - "after2", - "after1" - ] ); - } ); + // after/afterEach execute in LIFO order + "afterEach2", + "afterEach1", + "after2", + "after1" + ] ); + } ); - hooks.after( function( assert ) { assert.step( "after1" ); } ); - hooks.after( function( assert ) { assert.step( "after2" ); } ); + hooks.after( function( assert ) { assert.step( "after1" ); } ); + hooks.after( function( assert ) { assert.step( "after2" ); } ); - QUnit.test( "all hooks", function( assert ) { - assert.expect( 9 ); + QUnit.test( "all hooks", function( assert ) { + assert.expect( 9 ); + } ); } ); } ); diff --git a/test/main/promise.js b/test/main/promise.js index f8451c21e..fc2527327 100644 --- a/test/main/promise.js +++ b/test/main/promise.js @@ -19,205 +19,201 @@ function createMockPromise( assert, reject, value ) { return thenable; } -QUnit.module( "Module with Promise-aware before", { - before: function( assert ) { - assert.true( true ); - return {}; - } -} ); +QUnit.module( "Support for Promise", function() { -QUnit.test( "non-Promise", function( assert ) { - assert.expect( 1 ); -} ); + QUnit.module( "before hook with non-Promise", { + before: function( assert ) { + assert.true( true ); + return {}; + } + } ); + QUnit.test( "test", function( assert ) { + assert.expect( 1 ); + } ); -QUnit.module( "Module with Promise-aware before", { - before: function( assert ) { + QUnit.module( "before hook with Promise", { + before: function( assert ) { - // Adds 1 assertion - return createMockPromise( assert ); - } -} ); + // Adds 1 assertion + return createMockPromise( assert ); + } + } ); + QUnit.test( "test", function( assert ) { + assert.expect( 1 ); + } ); + + QUnit.module( "beforeEach hook with non-Promise", { + beforeEach: function( assert ) { + assert.true( true ); + return {}; + } + } ); + QUnit.test( "test", function( assert ) { + assert.expect( 1 ); + } ); -QUnit.test( "fulfilled Promise", function( assert ) { - assert.expect( 1 ); -} ); + QUnit.module( "beforeEach hook with Promise", { + beforeEach: function( assert ) { -QUnit.module( "Module with Promise-aware beforeEach", { - beforeEach: function( assert ) { - assert.true( true ); - return {}; - } -} ); + // Adds 1 assertion + return createMockPromise( assert ); + } + } ); + QUnit.test( "test", function( assert ) { + assert.expect( 1 ); + } ); + + QUnit.module( "afterEach hook with non-Promise", { + afterEach: function( assert ) { + assert.true( true ); + return {}; + } + } ); + QUnit.test( "test", function( assert ) { + assert.expect( 1 ); + } ); -QUnit.test( "non-Promise", function( assert ) { - assert.expect( 1 ); -} ); + QUnit.module( "afterEach hook with Promise", { + afterEach: function( assert ) { -QUnit.module( "Module with Promise-aware beforeEach", { - beforeEach: function( assert ) { + // Adds 1 assertion + return createMockPromise( assert ); + } + } ); + QUnit.test( "test", function( assert ) { + assert.expect( 1 ); + } ); + + QUnit.module( "after hook with non-Promise ", { + after: function( assert ) { + assert.true( true ); + return {}; + } + } ); + QUnit.test( "test", function( assert ) { + assert.expect( 1 ); + } ); - // Adds 1 assertion + QUnit.module( "after hook with Promise", { + after: function( assert ) { + + // Adds 1 assertion + return createMockPromise( assert ); + } + } ); + QUnit.test( "test", function( assert ) { + assert.expect( 1 ); + } ); + + QUnit.module( "all hooks with Promise", { + before: function( assert ) { + return createMockPromise( assert ); + }, + beforeEach: function( assert ) { + return createMockPromise( assert ); + }, + afterEach: function( assert ) { + return createMockPromise( assert ); + }, + after: function( assert ) { + return createMockPromise( assert ); + } + } ); + QUnit.test( "test", function( assert ) { + assert.expect( 5 ); return createMockPromise( assert ); - } -} ); + } ); -QUnit.test( "fulfilled Promise", function( assert ) { - assert.expect( 1 ); -} ); + QUnit.module( "tests", { + afterEach: function( assert ) { -QUnit.module( "Module with Promise-aware afterEach", { - afterEach: function( assert ) { - assert.true( true ); - return {}; - } -} ); + // Restore + if ( this.pushFailure ) { + assert.test.pushFailure = this.pushFailure; + } + } + } ); -QUnit.test( "non-Promise", function( assert ) { - assert.expect( 1 ); -} ); + QUnit.test( "non-Promise", function( assert ) { + assert.expect( 0 ); + return {}; + } ); -QUnit.module( "Module with Promise-aware afterEach", { - afterEach: function( assert ) { + QUnit.test( "fulfilled Promise", function( assert ) { + assert.expect( 1 ); // Adds 1 assertion return createMockPromise( assert ); - } -} ); + } ); -QUnit.test( "fulfilled Promise", function( assert ) { - assert.expect( 1 ); -} ); + QUnit.test( "fulfilled Promise and assert.async()", function( assert ) { + assert.expect( 2 ); -QUnit.module( "Module with Promise-aware after", { - after: function( assert ) { - assert.true( true ); - return {}; - } -} ); - -QUnit.test( "non-Promise", function( assert ) { - assert.expect( 1 ); -} ); - -QUnit.module( "Module with Promise-aware after", { - after: function( assert ) { + var done = assert.async(); + setTimeout( function() { + assert.true( true ); + done(); + }, 100 ); // Adds 1 assertion return createMockPromise( assert ); - } -} ); - -QUnit.test( "fulfilled Promise", function( assert ) { - assert.expect( 1 ); -} ); - -QUnit.module( "Module with Promise-aware everything", { - before: function( assert ) { - return createMockPromise( assert ); - }, - beforeEach: function( assert ) { - return createMockPromise( assert ); - }, - afterEach: function( assert ) { - return createMockPromise( assert ); - }, - after: function( assert ) { - return createMockPromise( assert ); - } -} ); - -QUnit.test( "fulfilled Promise", function( assert ) { - assert.expect( 5 ); - return createMockPromise( assert ); -} ); - -QUnit.module( "Promise-aware return values without beforeEach/afterEach" ); - -QUnit.test( "non-Promise", function( assert ) { - assert.expect( 0 ); - return {}; -} ); - -QUnit.test( "fulfilled Promise", function( assert ) { - assert.expect( 1 ); - - // Adds 1 assertion - return createMockPromise( assert ); -} ); - -QUnit.test( "fulfilled Promise with non-Promise async assertion", function( assert ) { - assert.expect( 2 ); - - var done = assert.async(); - setTimeout( function() { - assert.true( true ); - done(); - }, 100 ); - - // Adds 1 assertion - return createMockPromise( assert ); -} ); - -QUnit.module( "Promise-aware return values with rejections", { - afterEach: function( assert ) { - assert.test.pushFailure = this.pushFailure; - } -} ); - -QUnit.test( "rejected Promise with undefined value", function( assert ) { - assert.expect( 2 ); - - this.pushFailure = assert.test.pushFailure; - assert.test.pushFailure = function( message ) { - assert.strictEqual( - message, - "Promise rejected during \"rejected Promise with undefined value\": undefined" - ); - }; - - return createMockPromise( assert, true, undefined ); -} ); - -QUnit.test( "rejected Promise with error value", function( assert ) { - assert.expect( 2 ); - - this.pushFailure = assert.test.pushFailure; - assert.test.pushFailure = function( message ) { - assert.strictEqual( - message, - "Promise rejected during \"rejected Promise with error value\": this is an error" - ); - }; - - return createMockPromise( assert, true, new Error( "this is an error" ) ); -} ); - -QUnit.test( "rejected Promise with string value", function( assert ) { - assert.expect( 2 ); - - this.pushFailure = assert.test.pushFailure; - assert.test.pushFailure = function( message ) { - assert.strictEqual( - message, - "Promise rejected during \"rejected Promise with string value\": this is an error" - ); - }; - - return createMockPromise( assert, true, "this is an error" ); -} ); - -QUnit.test( "rejected Promise with async lock", function( assert ) { - assert.expect( 2 ); - - assert.async(); // Important! We don't explicitly release the async lock - - this.pushFailure = assert.test.pushFailure; - assert.test.pushFailure = function( message ) { - assert.strictEqual( - message, - "Promise rejected during \"rejected Promise with async lock\": this is an error" - ); - }; - - return createMockPromise( assert, true, "this is an error" ); + } ); + + QUnit.test( "rejected Promise with undefined value", function( assert ) { + assert.expect( 2 ); + + this.pushFailure = assert.test.pushFailure; + assert.test.pushFailure = function( message ) { + assert.strictEqual( + message, + "Promise rejected during \"rejected Promise with undefined value\": undefined" + ); + }; + + return createMockPromise( assert, true, undefined ); + } ); + + QUnit.test( "rejected Promise with error value", function( assert ) { + assert.expect( 2 ); + + this.pushFailure = assert.test.pushFailure; + assert.test.pushFailure = function( message ) { + assert.strictEqual( + message, + "Promise rejected during \"rejected Promise with error value\": this is an error" + ); + }; + + return createMockPromise( assert, true, new Error( "this is an error" ) ); + } ); + + QUnit.test( "rejected Promise with string value", function( assert ) { + assert.expect( 2 ); + + this.pushFailure = assert.test.pushFailure; + assert.test.pushFailure = function( message ) { + assert.strictEqual( + message, + "Promise rejected during \"rejected Promise with string value\": this is an error" + ); + }; + + return createMockPromise( assert, true, "this is an error" ); + } ); + + QUnit.test( "rejected Promise with async lock", function( assert ) { + assert.expect( 2 ); + + assert.async(); // Important! We don't explicitly release the async lock + + this.pushFailure = assert.test.pushFailure; + assert.test.pushFailure = function( message ) { + assert.strictEqual( + message, + "Promise rejected during \"rejected Promise with async lock\": this is an error" + ); + }; + + return createMockPromise( assert, true, "this is an error" ); + } ); } ); diff --git a/test/main/test.js b/test/main/test.js index 9d0ec3a31..d0f20a7e1 100644 --- a/test/main/test.js +++ b/test/main/test.js @@ -1,15 +1,15 @@ -QUnit.test( "expect query and multiple issue", function( assert ) { - assert.expect( 2 ); - assert.true( true ); - var expected = assert.expect(); - assert.equal( expected, 2 ); - assert.expect( expected + 1 ); - assert.true( true ); -} ); - -if ( typeof document !== "undefined" ) { +QUnit.module( "test", function() { + + QUnit.test( "read and change assert.expect() count", function( assert ) { + assert.expect( 2 ); + assert.true( true ); + var expected = assert.expect(); + assert.equal( expected, 2 ); + assert.expect( expected + 1 ); + assert.true( true ); + } ); - QUnit.module( "fixture", function( hooks ) { + ( typeof document !== "undefined" ? QUnit.module : QUnit.module.skip )( "fixture management", function( hooks ) { var failure = false, values = [ @@ -153,87 +153,101 @@ if ( typeof document !== "undefined" ) { } ); } ); -} + QUnit.module( "custom assertions" ); -QUnit.module( "custom assertions" ); + QUnit.assert.mod2 = function( value, expected, message ) { + var actual = value % 2; + this.pushResult( { + result: actual === expected, + actual: actual, + expected: expected, + message: message + } ); + }; + + QUnit.assert.testForPush = function( value, expected, message ) { + this.push( true, value, expected, message, false ); + }; -QUnit.assert.mod2 = function( value, expected, message ) { - var actual = value % 2; - this.pushResult( { - result: actual === expected, - actual: actual, - expected: expected, - message: message + QUnit.test( "mod2", function( assert ) { + assert.mod2( 2, 0, "2 % 2 == 0" ); + assert.mod2( 3, 1, "3 % 2 == 1" ); } ); -}; -QUnit.assert.testForPush = function( value, expected, message ) { - this.push( true, value, expected, message, false ); -}; + QUnit.test( "testForPush", function( assert ) { + QUnit.log( function( detail ) { + if ( detail.message === "should be call pushResult" ) { + assert.equal( detail.result, true ); + assert.equal( detail.actual, 1 ); + assert.equal( detail.expected, 1 ); + assert.equal( detail.message, "should be call pushResult" ); + assert.equal( detail.negative, false ); + } + } ); + assert.testForPush( 1, 1, "should be call pushResult" ); + } ); -QUnit.test( "mod2", function( assert ) { - assert.expect( 2 ); + QUnit.module( "aliases" ); - assert.mod2( 2, 0, "2 % 2 == 0" ); - assert.mod2( 3, 1, "3 % 2 == 1" ); -} ); + [ "todo", "skip", "only" ].forEach( function( flavor ) { + QUnit.test( "test." + flavor, function( assert ) { + assert.strictEqual( typeof QUnit.test[ flavor ], "function" ); + assert.strictEqual( QUnit[ flavor ], QUnit.test[ flavor ] ); + } ); + } ); -QUnit.test( "testForPush", function( assert ) { - assert.expect( 6 ); + QUnit.module( "test.skip", { + beforeEach: function( assert ) { - QUnit.log( function( detail ) { - if ( detail.message === "should be call pushResult" ) { - assert.equal( detail.result, true ); - assert.equal( detail.actual, 1 ); - assert.equal( detail.expected, 1 ); - assert.equal( detail.message, "should be call pushResult" ); - assert.equal( detail.negative, false ); + // Skip test hooks for skipped tests + assert.true( false, "skipped function" ); + throw "Error"; + }, + afterEach: function( assert ) { + assert.true( false, "skipped function" ); + throw "Error"; } } ); - assert.testForPush( 1, 1, "should be call pushResult" ); -} ); -QUnit.module( "aliases" ); + QUnit.skip( "skip blocks are skipped", function( assert ) { -[ "todo", "skip", "only" ].forEach( function( flavor ) { - QUnit.test( flavor, function( assert ) { - assert.true( QUnit.test[ flavor ] instanceof Function ); - assert.equal( QUnit[ flavor ], QUnit.test[ flavor ] ); + // This test callback won't run, even with broken code + assert.expect( 1000 ); + throw "Error"; } ); -} ); -QUnit.module( "QUnit.skip", { - beforeEach: function( assert ) { + QUnit.skip( "skip without function" ); - // Skip test hooks for skipped tests - assert.true( false, "skipped function" ); - throw "Error"; - }, - afterEach: function( assert ) { - assert.true( false, "skipped function" ); - throw "Error"; - } -} ); + QUnit.module( "missing callbacks" ); + + QUnit.test( "QUnit.test without a callback logs a descriptive error", function( assert ) { + assert.throws( function() { + QUnit.test( "should throw an error" ); + }, /You must provide a callback to QUnit.test\("should throw an error"\)/ ); + } ); -QUnit.skip( "test blocks are skipped", function( assert ) { + QUnit.test( "QUnit.todo without a callback logs a descriptive error", function( assert ) { + assert.throws( function() { + QUnit.todo( "should throw an error" ); + }, /You must provide a callback to QUnit.todo\("should throw an error"\)/ ); + } ); - // This test callback won't run, even with broken code - assert.expect( 1000 ); - throw "Error"; -} ); + ( function() { + var previousTestAssert; -QUnit.skip( "no function" ); + QUnit.module( "bad assertion context" ); -QUnit.module( "Missing Callbacks" ); + QUnit.test( "assertions after test finishes throws an error - part 1", function( assert ) { + assert.expect( 0 ); + previousTestAssert = assert; + } ); -QUnit.test( "QUnit.test without a callback logs a descriptive error", function( assert ) { - assert.throws( function() { - QUnit.test( "should throw an error" ); - }, /You must provide a callback to QUnit.test\("should throw an error"\)/ ); -} ); + QUnit.test( "assertions after test finishes throws an error - part 2", function( assert ) { + assert.expect( 1 ); + assert.throws( function() { + previousTestAssert.ok( true ); + }, /Assertion occurred after test had finished/ ); + } ); + }() ); -QUnit.test( "QUnit.todo without a callback logs a descriptive error", function( assert ) { - assert.throws( function() { - QUnit.todo( "should throw an error" ); - }, /You must provide a callback to QUnit.todo\("should throw an error"\)/ ); } ); diff --git a/test/main/utilities.js b/test/main/utilities.js index 66f6ff147..82a77ab4a 100644 --- a/test/main/utilities.js +++ b/test/main/utilities.js @@ -2,12 +2,10 @@ QUnit.module( "QUnit.objectType" ); -function Foo( ) { } +function Foo() { } function validateObjectType( item, expected ) { QUnit.test( "should properly detect " + expected, function( assert ) { - assert.expect( 1 ); - var actual = QUnit.objectType( item ); assert.equal( actual, expected ); } ); @@ -43,7 +41,6 @@ validateObjectType( undefined, "undefined" ); validateObjectType( { }, "object" ); validateObjectType( new Foo( ), "object" ); - if ( typeof Symbol === "function" ) { validateObjectType( Symbol( "HI!" ), "symbol" ); } @@ -63,7 +60,7 @@ maybeValidateObjectType( "async () => { }", "function" ); maybeValidateObjectType( "() => { }", "function" ); maybeValidateObjectType( "function* { }", "function" ); -QUnit.module( "extend" ); +QUnit.module( "QUnit.extend" ); QUnit.test( "appends to object", function( assert ) { var base = { foo: 1 }; diff --git a/test/onerror/inside-test.js b/test/onerror/inside-test.js index 9c17f3545..7df93e590 100644 --- a/test/onerror/inside-test.js +++ b/test/onerror/inside-test.js @@ -1,8 +1,8 @@ QUnit.module( "QUnit.onError", function() { - QUnit.test( "Should call pushFailure when inside a test", function( assert ) { + QUnit.test( "call pushFailure when inside a test", function( assert ) { assert.expect( 3 ); - QUnit.config.current.pushFailure = function( message, source ) { + assert.test.pushFailure = function( message, source ) { assert.strictEqual( message, "Error message", "Message is correct" ); assert.strictEqual( source, "filePath.js:1", "Source is correct" ); }; @@ -16,10 +16,10 @@ QUnit.module( "QUnit.onError", function() { assert.strictEqual( result, false, "onError should allow other error handlers to run" ); } ); - QUnit.test( "Should use stacktrace argument when it is present", function( assert ) { + QUnit.test( "use stacktrace argument", function( assert ) { assert.expect( 3 ); - QUnit.config.current.pushFailure = function( message, source ) { + assert.test.pushFailure = function( message, source ) { assert.strictEqual( message, "Error message", "Message is correct" ); assert.strictEqual( source, @@ -39,14 +39,14 @@ QUnit.module( "QUnit.onError", function() { } ); - QUnit.test( "Shouldn't push failure if ignoreGlobalErrors is enabled", function( assert ) { + QUnit.test( "ignore failure when ignoreGlobalErrors is enabled", function( assert ) { assert.expect( 1 ); - QUnit.config.current.pushFailure = function() { + assert.test.pushFailure = function() { assert.true( false, "No error should be pushed" ); }; - QUnit.config.current.ignoreGlobalErrors = true; + assert.test.ignoreGlobalErrors = true; var result = QUnit.onError( { message: "Error message", diff --git a/test/onerror/outside-test.js b/test/onerror/outside-test.js index 97813dc93..bc17f40f0 100644 --- a/test/onerror/outside-test.js +++ b/test/onerror/outside-test.js @@ -1,4 +1,4 @@ -QUnit.module( "Should create a test and call pushFailure when outside a test", function( hooks ) { +QUnit.module( "pushFailure outside a test", function( hooks ) { var originalPushResult; hooks.beforeEach( function() { @@ -13,7 +13,7 @@ QUnit.module( "Should create a test and call pushFailure when outside a test", f this.assert.strictEqual( this.testName, - "global failure", "Test is appropriately named" + "global failure", "new test implicitly created and appropriately named" ); this.assert.deepEqual( resultInfo, { @@ -21,7 +21,7 @@ QUnit.module( "Should create a test and call pushFailure when outside a test", f source: "filePath.js:1", result: false, actual: "actual" - }, "Expected assert.pushResult to be called with correct args" ); + }, "assert.pushResult arguments" ); }; } ); diff --git a/test/reporter-html/reporter-html.js b/test/reporter-html/reporter-html.js index b495ebc7b..dec6ef6c7 100644 --- a/test/reporter-html/reporter-html.js +++ b/test/reporter-html/reporter-html.js @@ -1,155 +1,148 @@ // The following tests need to run on their respective order QUnit.config.reorder = false; -QUnit.module( "", { - beforeEach: function() { - }, - afterEach: function( assert ) { - - // We can't use ok(false) inside script tags since some browsers - // don't evaluate script tags inserted through innerHTML after domready. - // Counting them before/after doesn't cover everything either as qunit-modulefilter - // is created before any test is ran. So use ids instead. - if ( document.getElementById( "qunit-unescaped-module" ) ) { - - // This can either be from in #qunit-modulefilter or #qunit-testresult - assert.true( false, "Unescaped module name" ); - } - if ( document.getElementById( "qunit-unescaped-test" ) ) { - assert.true( false, "Unescaped test name" ); - } - if ( document.getElementById( "qunit-unescaped-assertion" ) ) { - assert.true( false, "Unescaped test name" ); - } - } -} ); +QUnit.module( "HTML Reporter", function() { -QUnit.test( "", function( assert ) { - assert.expect( 1 ); - assert.true( true, "" ); -} ); - -QUnit.module( "display test info" ); + QUnit.module( "", { + beforeEach: function() { + }, + afterEach: function( assert ) { -QUnit.test( "Testing for running class", function( assert ) { - assert.expect( 1 ); + // We can't use ok(false) inside script tags since some browsers + // don't evaluate script tags inserted through innerHTML after domready. + // Counting them before/after doesn't cover everything either as qunit-modulefilter + // is created before any test is ran. So use ids instead. + if ( document.getElementById( "qunit-unescaped-module" ) ) { - assert.equal( document.querySelectorAll( ".running" ).length, 1 ); -} ); + // This can either be from in #qunit-modulefilter or #qunit-testresult + assert.true( false, "Unescaped module name" ); + } + if ( document.getElementById( "qunit-unescaped-test" ) ) { + assert.true( false, "Unescaped test name" ); + } + if ( document.getElementById( "qunit-unescaped-assertion" ) ) { + assert.true( false, "Unescaped test name" ); + } + } + } ); -QUnit.test( "running test name displayed", function( assert ) { - assert.expect( 2 ); + QUnit.test( "", function( assert ) { + assert.true( true, "" ); + } ); - var displaying = document.getElementById( "qunit-testresult" ); + QUnit.module( "Display" ); - assert.true( /running test name displayed/.test( displaying.innerHTML ), - "Expect test name to be found in displayed text" - ); - assert.true( /display test info/.test( displaying.innerHTML ), - "Expect module name to be found in displayed text" - ); -} ); + QUnit.test( "use 'running' class", function( assert ) { + assert.equal( document.querySelectorAll( "#qunit-testresult-display.running" ).length, 1 ); + } ); -QUnit.test( "running test suite progress displayed", function( assert ) { - assert.expect( 1 ); + QUnit.test( "running text", function( assert ) { + var display = document.getElementById( "qunit-testresult" ); - var displaying = document.getElementById( "qunit-testresult" ); + assert.true( /running text/.test( display.innerHTML ), "test name" ); + assert.true( /Display/.test( display.innerHTML ), "module name" ); + } ); - var expected = /\d+ \/ \d+ tests completed in \d+ milliseconds, with \d+ failed, \d+ skipped, and \d+ todo./; - assert.true( - expected.test( displaying.innerHTML ), - "Expect test suite progress to be found in displayed text" - ); -} ); + QUnit.test( "run progress", function( assert ) { + var display = document.getElementById( "qunit-testresult" ); -QUnit.module( "timing", { - getPreviousTest: function( assert ) { - return document.getElementById( "qunit-test-output-" + assert.test.testId ) - .previousSibling; - }, - filterClass: function( elements ) { - var i; - for ( i = 0; i < elements.length; i++ ) { - if ( /(^| )runtime( |$)/.test( elements[ i ].className ) ) { - return elements[ i ]; + var expected = /\d+ \/ \d+ tests completed in \d+ milliseconds, with \d+ failed, \d+ skipped, and \d+ todo./; + assert.true( + expected.test( display.innerHTML ), + "progress found in displayed text" + ); + } ); + + QUnit.module( "Duration", { + getPreviousTest: function( assert ) { + return document.getElementById( "qunit-test-output-" + assert.test.testId ) + .previousSibling; + }, + filterClass: function( elements ) { + var i; + for ( i = 0; i < elements.length; i++ ) { + if ( /(^| )runtime( |$)/.test( elements[ i ].className ) ) { + return elements[ i ]; + } + } + }, + afterEach: function( assert ) { + var done; + if ( this.delayNextSetup ) { + this.delayNextSetup = false; + done = assert.async(); + setTimeout( function() { + done(); + }, 101 ); } } - }, - afterEach: function( assert ) { - var done; - if ( this.delayNextSetup ) { - this.delayNextSetup = false; - done = assert.async(); - setTimeout( function() { - done(); - }, 101 ); - } - } -} ); + } ); -QUnit.test( "setup", function( assert ) { - assert.expect( 0 ); - this.delayNextSetup = true; -} ); + QUnit.test( "setup", function( assert ) { + assert.expect( 0 ); + this.delayNextSetup = true; + } ); -QUnit.test( "basics", function( assert ) { - assert.expect( 1 ); - var previous = this.getPreviousTest( assert ), - runtime = this.filterClass( previous.getElementsByTagName( "span" ) ); + QUnit.test( "basics", function( assert ) { + assert.expect( 1 ); + var previous = this.getPreviousTest( assert ), + runtime = this.filterClass( previous.getElementsByTagName( "span" ) ); - assert.true( /^\d+ ms$/.test( runtime.innerHTML ), "Runtime reported in ms" ); -} ); + assert.true( /^\d+ ms$/.test( runtime.innerHTML ), "Runtime reported in ms" ); + } ); -QUnit.test( "values", function( assert ) { - assert.expect( 2 ); + QUnit.test( "values", function( assert ) { + assert.expect( 2 ); - var basics = this.getPreviousTest( assert ), - setup = basics.previousSibling; + var basics = this.getPreviousTest( assert ), + setup = basics.previousSibling; - basics = this.filterClass( basics.getElementsByTagName( "span" ) ); - setup = this.filterClass( setup.getElementsByTagName( "span" ) ); + basics = this.filterClass( basics.getElementsByTagName( "span" ) ); + setup = this.filterClass( setup.getElementsByTagName( "span" ) ); - assert.true( parseInt( basics.innerHTML, 10 ) < 100, - "Fast runtime for trivial test" - ); - assert.true( parseInt( setup.innerHTML, 10 ) > 100, - "Runtime includes beforeEach" - ); -} ); + assert.true( parseInt( basics.innerHTML, 10 ) < 100, + "Fast runtime for trivial test" + ); + assert.true( parseInt( setup.innerHTML, 10 ) > 100, + "Runtime includes beforeEach" + ); + } ); -QUnit.module( "source" ); + QUnit.module( "Stack trace" ); -QUnit.test( "setup", function( assert ) { - assert.expect( 0 ); -} ); + QUnit.test( "setup", function( assert ) { + assert.expect( 0 ); + } ); -QUnit.test( "logs location", function( assert ) { - var previous = document.getElementById( "qunit-test-output-" + assert.test.testId ) - .previousSibling; - var source = previous.lastChild; - var err = new Error(); - - // Verify QUnit supported stack trace - if ( !err.stack ) { - assert.equal( - /(^| )qunit-source( |$)/.test( source.className ), - false, - "Don't add source information on unsupported environments" - ); - return; - } + QUnit.test( "logs location", function( assert ) { + var previous = document.getElementById( "qunit-test-output-" + assert.test.testId ) + .previousSibling; + var source = previous.lastChild; + var err = new Error(); + + // Verify QUnit supported stack trace + if ( !err.stack ) { + assert.equal( + /(^| )qunit-source( |$)/.test( source.className ), + false, + "Don't add source information on unsupported environments" + ); + return; + } - assert.true( /(^| )qunit-source( |$)/.test( source.className ), "Source element exists" ); - assert.equal( source.firstChild.innerHTML, "Source: " ); + assert.true( /(^| )qunit-source( |$)/.test( source.className ), "Source element exists" ); + assert.equal( source.firstChild.innerHTML, "Source: " ); - // The file test/reporter-html/reporter-html.js is a direct reference to this test file - assert.true( /\/test\/reporter-html\/reporter-html\.js:\d+/.test( source.innerHTML ), - "Source references to the current file and line number" - ); -} ); + // The file test/reporter-html/reporter-html.js is a direct reference to this test file + assert.true( /\/test\/reporter-html\/reporter-html\.js:\d+/.test( source.innerHTML ), + "Source references to the current file and line number" + ); + } ); + + QUnit.test( "disables autocomplete on module filter", function( assert ) { + var moduleFilterSearch = document.getElementById( "qunit-modulefilter-search" ); -QUnit.test( "disables autocomplete on module filter", function( assert ) { - var moduleFilterSearch = document.getElementById( "qunit-modulefilter-search" ); + assert.equal( moduleFilterSearch.autocomplete, "off" ); + } ); - assert.equal( moduleFilterSearch.autocomplete, "off" ); } ); diff --git a/test/reporter-html/unhandled-rejection.js b/test/reporter-html/unhandled-rejection.js index 5e3fd5762..ec55dfa60 100644 --- a/test/reporter-html/unhandled-rejection.js +++ b/test/reporter-html/unhandled-rejection.js @@ -60,8 +60,8 @@ if ( HAS_UNHANDLED_REJECTION_HANDLER ) { }; } ); - hooks.afterEach( function() { - QUnit.config.current.pushResult = originalPushResult; + hooks.afterEach( function( assert ) { + assert.pushResult = originalPushResult; } ); // Actual test (outside QUnit.test context) diff --git a/test/reporter-html/window-onerror-preexisting-handler.js b/test/reporter-html/window-onerror-preexisting-handler.js index 2a3438532..5a8c19ec1 100644 --- a/test/reporter-html/window-onerror-preexisting-handler.js +++ b/test/reporter-html/window-onerror-preexisting-handler.js @@ -15,7 +15,7 @@ QUnit.module( "window.onerror (with preexisting handler)", function( hooks ) { QUnit.onError = originalQUnitOnError; } ); - QUnit.test( "Should call QUnit.onError if handler returns false", function( assert ) { + QUnit.test( "call QUnit.onError if handler returns false", function( assert ) { assert.expect( 1 ); onerrorReturnValue = false; @@ -27,7 +27,7 @@ QUnit.module( "window.onerror (with preexisting handler)", function( hooks ) { window.onerror( "An error message", "filename.js", 1 ); } ); - QUnit.test( "Should call QUnit.onError if handler returns void 0", function( assert ) { + QUnit.test( "call QUnit.onError if handler returns void 0", function( assert ) { assert.expect( 1 ); onerrorReturnValue = void 0; @@ -39,7 +39,7 @@ QUnit.module( "window.onerror (with preexisting handler)", function( hooks ) { window.onerror( "An error message", "filename.js", 1 ); } ); - QUnit.test( "Should call QUnit.onError if handler returns truthy", function( assert ) { + QUnit.test( "call QUnit.onError if handler returns truthy", function( assert ) { assert.expect( 1 ); onerrorReturnValue = "truthy value"; @@ -51,7 +51,7 @@ QUnit.module( "window.onerror (with preexisting handler)", function( hooks ) { window.onerror( "An error message", "filename.js", 1 ); } ); - QUnit.test( "Should not handle error if other handler returns true", function( assert ) { + QUnit.test( "ignore error if other handler returns true", function( assert ) { assert.expect( 1 ); onerrorReturnValue = true; @@ -65,7 +65,7 @@ QUnit.module( "window.onerror (with preexisting handler)", function( hooks ) { assert.strictEqual( result, true, "Our error handler should have returned true" ); } ); - QUnit.test( "window.onerror handler should be called on window", function( assert ) { + QUnit.test( "window.onerror handler is called on window", function( assert ) { assert.expect( 1 ); QUnit.onError = function() {}; @@ -75,7 +75,7 @@ QUnit.module( "window.onerror (with preexisting handler)", function( hooks ) { assert.strictEqual( onerrorCallingContext, window, "Handler called with correct context" ); } ); - QUnit.test( "Should return QUnit.error return value if it is called", function( assert ) { + QUnit.test( "forward return value of QUnit.error", function( assert ) { assert.expect( 1 ); var expected = {}; diff --git a/test/reporter-html/window-onerror.js b/test/reporter-html/window-onerror.js index 729d79445..65969278d 100644 --- a/test/reporter-html/window-onerror.js +++ b/test/reporter-html/window-onerror.js @@ -9,7 +9,7 @@ QUnit.module( "window.onerror (no preexisting handler)", function( hooks ) { QUnit.onError = originalQUnitOnError; } ); - QUnit.test( "Should call QUnit.onError", function( assert ) { + QUnit.test( "call QUnit.onError", function( assert ) { assert.expect( 1 ); QUnit.onError = function() { @@ -19,7 +19,7 @@ QUnit.module( "window.onerror (no preexisting handler)", function( hooks ) { window.onerror( "An error message", "filename.js", 1 ); } ); - QUnit.test( "Should extract stacktrace if it is available", function( assert ) { + QUnit.test( "extract stacktrace", function( assert ) { assert.expect( 1 ); var errorObj = { @@ -34,7 +34,7 @@ QUnit.module( "window.onerror (no preexisting handler)", function( hooks ) { } ); - QUnit.test( "Should return QUnit.error return value if it is called", function( assert ) { + QUnit.test( "forward return value of QUnit.error", function( assert ) { assert.expect( 1 ); var expected = {}; diff --git a/test/setTimeout.js b/test/setTimeout.js index aca3ba29f..e16799efc 100644 --- a/test/setTimeout.js +++ b/test/setTimeout.js @@ -1,21 +1,21 @@ -( function( window ) { +( function( globalThis ) { - QUnit.module( "Module that mucks with time", { + QUnit.module( "Support mocked setTimeout", { beforeEach: function() { - this.setTimeout = window.setTimeout; - window.setTimeout = function() {}; + this.setTimeout = globalThis.setTimeout; + globalThis.setTimeout = function() {}; }, afterEach: function() { - window.setTimeout = this.setTimeout; + globalThis.setTimeout = this.setTimeout; } } ); - QUnit.test( "just a test", function( assert ) { + QUnit.test( "test one", function( assert ) { assert.true( true ); } ); - QUnit.test( "just a test", function( assert ) { + QUnit.test( "test two", function( assert ) { assert.true( true ); } );