diff options
author | Oleg Gaidarenko <markelog@gmail.com> | 2015-09-03 04:46:31 +0300 |
---|---|---|
committer | Oleg Gaidarenko <markelog@gmail.com> | 2015-09-07 20:14:59 +0300 |
commit | 4543815eeda0d7299e701311ca4ac38f23dbaf3a (patch) | |
tree | f5a0374836bf1b0c0b748098a14075093ea8de7b /test/unit/callbacks.js | |
parent | c530661629ac713a3ccab9691773cc6de5e84759 (diff) | |
download | jquery-4543815eeda0d7299e701311ca4ac38f23dbaf3a.tar.gz jquery-4543815eeda0d7299e701311ca4ac38f23dbaf3a.zip |
Tests: Partially use new qunit interface
http://qunitjs.com/upgrade-guide-2.x/
For most of the boring work was used
https://github.com/apsdehal/qunit-migrate package
However, it can't update local qunit helpers, plus in some places
old QUnit.asyncTest signature is still used
Ref b930d14ce64937e9478405eee2828d4da091d2cb
Fixes gh-2540
Diffstat (limited to 'test/unit/callbacks.js')
-rw-r--r-- | test/unit/callbacks.js | 130 |
1 files changed, 65 insertions, 65 deletions
diff --git a/test/unit/callbacks.js b/test/unit/callbacks.js index 089047f03..c6c379ded 100644 --- a/test/unit/callbacks.js +++ b/test/unit/callbacks.js @@ -1,4 +1,4 @@ -module( "callbacks", { +QUnit.module( "callbacks", { teardown: moduleTeardown } ); @@ -63,9 +63,9 @@ jQuery.each( tests, function( strFlags, resultString ) { "object": objectFlags }, function( flagsTypes, flags ) { - test( "jQuery.Callbacks( " + showFlags( flags ) + " ) - " + filterLabel, function() { + QUnit.test( "jQuery.Callbacks( " + showFlags( flags ) + " ) - " + filterLabel, function( assert ) { - expect( 29 ); + assert.expect( 29 ); var cblist, results = resultString.split( /\s+/ ); @@ -73,32 +73,32 @@ jQuery.each( tests, function( strFlags, resultString ) { // Basic binding and firing output = "X"; cblist = jQuery.Callbacks( flags ); - strictEqual( cblist.locked(), false, ".locked() initially false" ); - strictEqual( cblist.disabled(), false, ".disabled() initially false" ); - strictEqual( cblist.fired(), false, ".fired() initially false" ); + assert.strictEqual( cblist.locked(), false, ".locked() initially false" ); + assert.strictEqual( cblist.disabled(), false, ".disabled() initially false" ); + assert.strictEqual( cblist.fired(), false, ".fired() initially false" ); cblist.add( function( str ) { output += str; } ); - strictEqual( cblist.fired(), false, ".fired() still false after .add" ); + assert.strictEqual( cblist.fired(), false, ".fired() still false after .add" ); cblist.fire( "A" ); - strictEqual( output, "XA", "Basic binding and firing" ); - strictEqual( cblist.fired(), true, ".fired() detects firing" ); + assert.strictEqual( output, "XA", "Basic binding and firing" ); + assert.strictEqual( cblist.fired(), true, ".fired() detects firing" ); output = "X"; cblist.disable(); cblist.add( function( str ) { output += str; } ); - strictEqual( output, "X", "Adding a callback after disabling" ); + assert.strictEqual( output, "X", "Adding a callback after disabling" ); cblist.fire( "A" ); - strictEqual( output, "X", "Firing after disabling" ); - strictEqual( cblist.disabled(), true, ".disabled() becomes true" ); - strictEqual( cblist.locked(), true, "disabling locks" ); + assert.strictEqual( output, "X", "Firing after disabling" ); + assert.strictEqual( cblist.disabled(), true, ".disabled() becomes true" ); + assert.strictEqual( cblist.locked(), true, "disabling locks" ); // Emptying while firing (#13517) cblist = jQuery.Callbacks( flags ); cblist.add( cblist.empty ); cblist.add( function() { - ok( false, "not emptied" ); + assert.ok( false, "not emptied" ); } ); cblist.fire(); @@ -106,7 +106,7 @@ jQuery.each( tests, function( strFlags, resultString ) { cblist = jQuery.Callbacks( flags ); cblist.add( cblist.disable ); cblist.add( function() { - ok( false, "not disabled" ); + assert.ok( false, "not disabled" ); } ); cblist.fire(); @@ -114,18 +114,18 @@ jQuery.each( tests, function( strFlags, resultString ) { output = "X"; cblist = jQuery.Callbacks( flags ); cblist.add( function() { - equal( this, window, "Basic binding and firing (context)" ); + assert.equal( this, window, "Basic binding and firing (context)" ); output += Array.prototype.join.call( arguments, "" ); } ); cblist.fireWith( window, [ "A", "B" ] ); - strictEqual( output, "XAB", "Basic binding and firing (arguments)" ); + assert.strictEqual( output, "XAB", "Basic binding and firing (arguments)" ); // fireWith with no arguments output = ""; cblist = jQuery.Callbacks( flags ); cblist.add( function() { - equal( this, window, "fireWith with no arguments (context is window)" ); - strictEqual( arguments.length, 0, "fireWith with no arguments (no arguments)" ); + assert.equal( this, window, "fireWith with no arguments (context is window)" ); + assert.strictEqual( arguments.length, 0, "fireWith with no arguments (no arguments)" ); } ); cblist.fireWith(); @@ -135,7 +135,7 @@ jQuery.each( tests, function( strFlags, resultString ) { cblist.add( outputA, outputB, outputC ); cblist.remove( outputB, outputC ); cblist.fire(); - strictEqual( output, "XA", "Basic binding, removing and firing" ); + assert.strictEqual( output, "XA", "Basic binding, removing and firing" ); // Empty output = "X"; @@ -145,7 +145,7 @@ jQuery.each( tests, function( strFlags, resultString ) { cblist.add( outputC ); cblist.empty(); cblist.fire(); - strictEqual( output, "X", "Empty" ); + assert.strictEqual( output, "X", "Empty" ); // Locking output = "X"; @@ -161,8 +161,8 @@ jQuery.each( tests, function( strFlags, resultString ) { cblist.add( function( str ) { output += str; } ); - strictEqual( output, "X", "Lock early" ); - strictEqual( cblist.locked(), true, "Locking reflected in accessor" ); + assert.strictEqual( output, "X", "Lock early" ); + assert.strictEqual( cblist.locked(), true, "Locking reflected in accessor" ); // Locking while firing (gh-1990) output = "X"; @@ -172,7 +172,7 @@ jQuery.each( tests, function( strFlags, resultString ) { output += str; } ); cblist.fire( "A" ); - strictEqual( output, "XA", "Locking doesn't abort execution (gh-1990)" ); + assert.strictEqual( output, "XA", "Locking doesn't abort execution (gh-1990)" ); // Ordering output = "X"; @@ -182,7 +182,7 @@ jQuery.each( tests, function( strFlags, resultString ) { outputA(); }, outputB ); cblist.fire(); - strictEqual( output, results.shift(), "Proper ordering" ); + assert.strictEqual( output, results.shift(), "Proper ordering" ); // Add and fire again output = "X"; @@ -190,11 +190,11 @@ jQuery.each( tests, function( strFlags, resultString ) { cblist.add( outputC ); outputA(); }, outputB ); - strictEqual( output, results.shift(), "Add after fire" ); + assert.strictEqual( output, results.shift(), "Add after fire" ); output = "X"; cblist.fire(); - strictEqual( output, results.shift(), "Fire again" ); + assert.strictEqual( output, results.shift(), "Fire again" ); // Multiple fire output = "X"; @@ -203,20 +203,20 @@ jQuery.each( tests, function( strFlags, resultString ) { output += str; } ); cblist.fire( "A" ); - strictEqual( output, "XA", "Multiple fire (first fire)" ); + assert.strictEqual( output, "XA", "Multiple fire (first fire)" ); output = "X"; cblist.add( function( str ) { output += str; } ); - strictEqual( output, results.shift(), "Multiple fire (first new callback)" ); + assert.strictEqual( output, results.shift(), "Multiple fire (first new callback)" ); output = "X"; cblist.fire( "B" ); - strictEqual( output, results.shift(), "Multiple fire (second fire)" ); + assert.strictEqual( output, results.shift(), "Multiple fire (second fire)" ); output = "X"; cblist.add( function( str ) { output += str; } ); - strictEqual( output, results.shift(), "Multiple fire (second new callback)" ); + assert.strictEqual( output, results.shift(), "Multiple fire (second new callback)" ); // Return false output = "X"; @@ -224,12 +224,12 @@ jQuery.each( tests, function( strFlags, resultString ) { cblist.add( outputA, function() { return false; }, outputB ); cblist.add( outputA ); cblist.fire(); - strictEqual( output, results.shift(), "Callback returning false" ); + assert.strictEqual( output, results.shift(), "Callback returning false" ); // Add another callback (to control lists with memory do not fire anymore) output = "X"; cblist.add( outputC ); - strictEqual( output, results.shift(), "Adding a callback after one returned false" ); + assert.strictEqual( output, results.shift(), "Adding a callback after one returned false" ); // Callbacks are not iterated output = ""; @@ -243,7 +243,7 @@ jQuery.each( tests, function( strFlags, resultString ) { cblist.add( handler ); cblist.add( handler ); cblist.fire(); - strictEqual( output, results.shift(), "No callback iteration" ); + assert.strictEqual( output, results.shift(), "No callback iteration" ); } ); } ); } ); @@ -251,9 +251,9 @@ jQuery.each( tests, function( strFlags, resultString ) { } )(); -test( "jQuery.Callbacks( options ) - options are copied", function() { +QUnit.test( "jQuery.Callbacks( options ) - options are copied", function( assert ) { - expect( 1 ); + assert.expect( 1 ); var options = { "unique": true @@ -261,16 +261,16 @@ test( "jQuery.Callbacks( options ) - options are copied", function() { cb = jQuery.Callbacks( options ), count = 0, fn = function() { - ok( !( count++ ), "called once" ); + assert.ok( !( count++ ), "called once" ); }; options[ "unique" ] = false; cb.add( fn, fn ); cb.fire(); } ); -test( "jQuery.Callbacks.fireWith - arguments are copied", function() { +QUnit.test( "jQuery.Callbacks.fireWith - arguments are copied", function( assert ) { - expect( 1 ); + assert.expect( 1 ); var cb = jQuery.Callbacks( "memory" ), args = [ "hello" ]; @@ -279,28 +279,28 @@ test( "jQuery.Callbacks.fireWith - arguments are copied", function() { args[ 0 ] = "world"; cb.add( function( hello ) { - strictEqual( hello, "hello", "arguments are copied internally" ); + assert.strictEqual( hello, "hello", "arguments are copied internally" ); } ); } ); -test( "jQuery.Callbacks.remove - should remove all instances", function() { +QUnit.test( "jQuery.Callbacks.remove - should remove all instances", function( assert ) { - expect( 1 ); + assert.expect( 1 ); var cb = jQuery.Callbacks(); function fn() { - ok( false, "function wasn't removed" ); + assert.ok( false, "function wasn't removed" ); } cb.add( fn, fn, function() { - ok( true, "end of test" ); + assert.ok( true, "end of test" ); } ).remove( fn ).fire(); } ); -test( "jQuery.Callbacks.has", function() { +QUnit.test( "jQuery.Callbacks.has", function( assert ) { - expect( 13 ); + assert.expect( 13 ); var cb = jQuery.Callbacks(); function getA() { @@ -313,48 +313,48 @@ test( "jQuery.Callbacks.has", function() { return "C"; } cb.add( getA, getB, getC ); - strictEqual( cb.has(), true, "No arguments to .has() returns whether callback function(s) are attached or not" ); - strictEqual( cb.has( getA ), true, "Check if a specific callback function is in the Callbacks list" ); + assert.strictEqual( cb.has(), true, "No arguments to .has() returns whether callback function(s) are attached or not" ); + assert.strictEqual( cb.has( getA ), true, "Check if a specific callback function is in the Callbacks list" ); cb.remove( getB ); - strictEqual( cb.has( getB ), false, "Remove a specific callback function and make sure its no longer there" ); - strictEqual( cb.has( getA ), true, "Remove a specific callback function and make sure other callback function is still there" ); + assert.strictEqual( cb.has( getB ), false, "Remove a specific callback function and make sure its no longer there" ); + assert.strictEqual( cb.has( getA ), true, "Remove a specific callback function and make sure other callback function is still there" ); cb.empty(); - strictEqual( cb.has(), false, "Empty list and make sure there are no callback function(s)" ); - strictEqual( cb.has( getA ), false, "Check for a specific function in an empty() list" ); + assert.strictEqual( cb.has(), false, "Empty list and make sure there are no callback function(s)" ); + assert.strictEqual( cb.has( getA ), false, "Check for a specific function in an empty() list" ); cb.add( getA, getB, function() { - strictEqual( cb.has(), true, "Check if list has callback function(s) from within a callback function" ); - strictEqual( cb.has( getA ), true, "Check if list has a specific callback from within a callback function" ); + assert.strictEqual( cb.has(), true, "Check if list has callback function(s) from within a callback function" ); + assert.strictEqual( cb.has( getA ), true, "Check if list has a specific callback from within a callback function" ); } ).fire(); - strictEqual( cb.has(), true, "Callbacks list has callback function(s) after firing" ); + assert.strictEqual( cb.has(), true, "Callbacks list has callback function(s) after firing" ); cb.disable(); - strictEqual( cb.has(), false, "disabled() list has no callback functions (returns false)" ); - strictEqual( cb.has( getA ), false, "Check for a specific function in a disabled() list" ); + assert.strictEqual( cb.has(), false, "disabled() list has no callback functions (returns false)" ); + assert.strictEqual( cb.has( getA ), false, "Check for a specific function in a disabled() list" ); cb = jQuery.Callbacks( "unique" ); cb.add( getA ); cb.add( getA ); - strictEqual( cb.has(), true, "Check if unique list has callback function(s) attached" ); + assert.strictEqual( cb.has(), true, "Check if unique list has callback function(s) attached" ); cb.lock(); - strictEqual( cb.has(), false, "locked() list is empty and returns false" ); + assert.strictEqual( cb.has(), false, "locked() list is empty and returns false" ); } ); -test( "jQuery.Callbacks() - adding a string doesn't cause a stack overflow", function() { +QUnit.test( "jQuery.Callbacks() - adding a string doesn't cause a stack overflow", function( assert ) { - expect( 1 ); + assert.expect( 1 ); jQuery.Callbacks().add( "hello world" ); - ok( true, "no stack overflow" ); + assert.ok( true, "no stack overflow" ); } ); -test( "jQuery.Callbacks() - disabled callback doesn't fire (gh-1790)", function() { +QUnit.test( "jQuery.Callbacks() - disabled callback doesn't fire (gh-1790)", function( assert ) { - expect( 1 ); + assert.expect( 1 ); var cb = jQuery.Callbacks(), fired = false, @@ -364,5 +364,5 @@ test( "jQuery.Callbacks() - disabled callback doesn't fire (gh-1790)", function( cb.empty(); cb.add( shot ); cb.fire(); - ok( !fired, "Disabled callback function didn't fire" ); + assert.ok( !fired, "Disabled callback function didn't fire" ); } ); |