QUnit.test( "jQuery.Callbacks( " + showFlags( flags ) + " ) - " + filterLabel, function( assert ) {
- assert.expect( 29 );
+ assert.expect( 28 );
var cblist,
results = resultString.split( /\s+/ );
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 ) {
+ cblist.add(function( str ) {
output += str;
- } );
+ });
assert.strictEqual( cblist.fired(), false, ".fired() still false after .add" );
cblist.fire( "A" );
assert.strictEqual( output, "XA", "Basic binding and firing" );
assert.strictEqual( cblist.fired(), true, ".fired() detects firing" );
output = "X";
cblist.disable();
- cblist.add( function( str ) {
+ cblist.add(function( str ) {
output += str;
- } );
+ });
assert.strictEqual( output, "X", "Adding a callback after disabling" );
- cblist.fire( "A" );
+ cblist.fire("A");
assert.strictEqual( output, "X", "Firing after disabling" );
assert.strictEqual( cblist.disabled(), true, ".disabled() becomes true" );
assert.strictEqual( cblist.locked(), true, "disabling locks" );
// Basic binding and firing (context, arguments)
output = "X";
cblist = jQuery.Callbacks( flags );
- cblist.add( function() {
+ cblist.add(function() {
assert.equal( this, window, "Basic binding and firing (context)" );
output += Array.prototype.join.call( arguments, "" );
- } );
+ });
cblist.fireWith( window, [ "A", "B" ] );
assert.strictEqual( output, "XAB", "Basic binding and firing (arguments)" );
// fireWith with no arguments
output = "";
cblist = jQuery.Callbacks( flags );
- cblist.add( function() {
+ cblist.add(function() {
assert.equal( this, window, "fireWith with no arguments (context is window)" );
assert.strictEqual( arguments.length, 0, "fireWith with no arguments (no arguments)" );
- } );
+ });
cblist.fireWith();
// Basic binding, removing and firing
// Locking
output = "X";
cblist = jQuery.Callbacks( flags );
- cblist.add( function( str ) {
+ cblist.add(function( str ) {
output += str;
- } );
+ });
cblist.lock();
- cblist.add( function( str ) {
+ cblist.add(function( str ) {
output += str;
- } );
- cblist.fire( "A" );
- cblist.add( function( str ) {
+ });
+ cblist.fire("A");
+ cblist.add(function( str ) {
output += str;
- } );
+ });
assert.strictEqual( output, "X", "Lock early" );
assert.strictEqual( cblist.locked(), true, "Locking reflected in accessor" );
- // Locking while firing (gh-1990)
- output = "X";
- cblist = jQuery.Callbacks( flags );
- cblist.add( cblist.lock );
- cblist.add( function( str ) {
- output += str;
- } );
- cblist.fire( "A" );
- assert.strictEqual( output, "XA", "Locking doesn't abort execution (gh-1990)" );
-
// Ordering
output = "X";
cblist = jQuery.Callbacks( flags );
- cblist.add( function() {
+ cblist.add(function() {
cblist.add( outputC );
outputA();
}, outputB );
// Add and fire again
output = "X";
- cblist.add( function() {
+ cblist.add(function() {
cblist.add( outputC );
outputA();
}, outputB );
// Multiple fire
output = "X";
cblist = jQuery.Callbacks( flags );
- cblist.add( function( str ) {
+ cblist.add(function( str ) {
output += str;
- } );
- cblist.fire( "A" );
+ });
+ cblist.fire("A");
assert.strictEqual( output, "XA", "Multiple fire (first fire)" );
output = "X";
- cblist.add( function( str ) {
+ cblist.add(function( str ) {
output += str;
- } );
+ });
assert.strictEqual( output, results.shift(), "Multiple fire (first new callback)" );
output = "X";
- cblist.fire( "B" );
+ cblist.fire("B");
assert.strictEqual( output, results.shift(), "Multiple fire (second fire)" );
output = "X";
- cblist.add( function( str ) {
+ cblist.add(function( str ) {
output += str;
- } );
+ });
assert.strictEqual( output, results.shift(), "Multiple fire (second new callback)" );
// Return false