]> source.dussan.org Git - jquery.git/commitdiff
Fixing style for deferred.js unit tests. Close gh-973.
authorErick Ruiz de Chavez <erickrdch@gmail.com>
Tue, 16 Oct 2012 12:16:53 +0000 (08:16 -0400)
committerDave Methvin <dave.methvin@gmail.com>
Tue, 16 Oct 2012 12:24:18 +0000 (08:24 -0400)
Close jquery/2012-dev-summit/#56

src/sizzle
test/unit/deferred.js

index 56d3b2f2a7843248a9fa2d8e243d47defb373446..3ed4e970e262230c799eaf24cc6d889828a3d6f3 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 56d3b2f2a7843248a9fa2d8e243d47defb373446
+Subproject commit 3ed4e970e262230c799eaf24cc6d889828a3d6f3
index a786a05a9332264ba43f50cbdfad6347a2a054ac..80827c64170723ea00b77694280ea631cffd70f2 100644 (file)
@@ -1,4 +1,6 @@
-module("deferred", { teardown: moduleTeardown });
+module( "deferred", {
+       teardown: moduleTeardown
+});
 
 jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
 
@@ -6,7 +8,7 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
                return withNew ? new jQuery.Deferred( fn ) : jQuery.Deferred( fn );
        }
 
-       test("jQuery.Deferred" + withNew, function() {
+       test( "jQuery.Deferred" + withNew, function() {
 
                expect( 23 );
 
@@ -15,28 +17,28 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
                strictEqual( defer.pipe, defer.then, "pipe is an alias of then" );
 
                createDeferred().resolve().done(function() {
-                       ok( true , "Success on resolve" );
+                       ok( true, "Success on resolve" );
                        strictEqual( this.state(), "resolved", "Deferred is resolved (state)" );
                }).fail(function() {
-                       ok( false , "Error on resolve" );
+                       ok( false, "Error on resolve" );
                }).always(function() {
-                       ok( true , "Always callback on resolve" );
+                       ok( true, "Always callback on resolve" );
                });
 
                createDeferred().reject().done(function() {
-                       ok( false , "Success on reject" );
+                       ok( false, "Success on reject" );
                }).fail(function() {
-                       ok( true , "Error on reject" );
+                       ok( true, "Error on reject" );
                        strictEqual( this.state(), "rejected", "Deferred is rejected (state)" );
                }).always(function() {
-                       ok( true , "Always callback on reject" );
+                       ok( true, "Always callback on reject" );
                });
 
                createDeferred(function( defer ) {
-                       ok( this === defer , "Defer passed as this & first argument" );
-                       this.resolve( "done" );
-               }).done( function( value ) {
-                       strictEqual( value , "done" , "Passed function executed" );
+                       ok( this === defer, "Defer passed as this & first argument" );
+                       this.resolve("done");
+               }).done(function( value ) {
+                       strictEqual( value, "done", "Passed function executed" );
                });
 
                createDeferred(function( defer ) {
@@ -56,14 +58,14 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
                });
 
                jQuery.expandedEach = jQuery.each;
-               jQuery.expandedEach( "resolve reject".split( " " ), function( _, change ) {
-                       createDeferred( function( defer ) {
+               jQuery.expandedEach( "resolve reject".split(" "), function( _, change ) {
+                       createDeferred(function( defer ) {
                                strictEqual( defer.state(), "pending", "pending after creation" );
                                var checked = 0;
                                defer.progress(function( value ) {
                                        strictEqual( value, checked, "Progress: right value (" + value + ") received" );
                                });
-                               for( checked = 0; checked < 3 ; checked++ ) {
+                               for ( checked = 0; checked < 3; checked++ ) {
                                        defer.notify( checked );
                                }
                                strictEqual( defer.state(), "pending", "pending after notification" );
@@ -73,7 +75,7 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
                        });
                });
        });
-} );
+});
 
 
 test( "jQuery.Deferred - chainability", function() {
@@ -83,23 +85,23 @@ test( "jQuery.Deferred - chainability", function() {
        expect( 10 );
 
        jQuery.expandedEach = jQuery.each;
-       jQuery.expandedEach( "resolve reject notify resolveWith rejectWith notifyWith done fail progress always".split( " " ), function( _, method ) {
-               var object = { m: defer[ method ] };
+       jQuery.expandedEach( "resolve reject notify resolveWith rejectWith notifyWith done fail progress always".split(" "), function( _, method ) {
+               var object = {
+                       m: defer[ method ]
+               };
                strictEqual( object.m(), object, method + " is chainable" );
        });
 });
 
 test( "jQuery.Deferred.then - filtering (done)", function() {
 
-       expect(4);
+       expect( 4 );
 
-       var defer = jQuery.Deferred(),
+       var value1, value2, value3,
+               defer = jQuery.Deferred(),
                piped = defer.then(function( a, b ) {
                        return a * b;
-               }),
-               value1,
-               value2,
-               value3;
+               });
 
        piped.done(function( result ) {
                value3 = result;
@@ -127,15 +129,13 @@ test( "jQuery.Deferred.then - filtering (done)", function() {
 
 test( "jQuery.Deferred.then - filtering (fail)", function() {
 
-       expect(4);
+       expect( 4 );
 
-       var defer = jQuery.Deferred(),
+       var value1, value2, value3,
+               defer = jQuery.Deferred(),
                piped = defer.then( null, function( a, b ) {
                        return a * b;
-               } ),
-               value1,
-               value2,
-               value3;
+               });
 
        piped.fail(function( result ) {
                value3 = result;
@@ -154,7 +154,7 @@ test( "jQuery.Deferred.then - filtering (fail)", function() {
 
        jQuery.Deferred().resolve().then( null, function() {
                ok( false, "then should not be called on resolve" );
-       } );
+       });
 
        jQuery.Deferred().reject().then( null, jQuery.noop ).fail(function( value ) {
                strictEqual( value, undefined, "then fail callback can return undefined/null" );
@@ -163,15 +163,13 @@ test( "jQuery.Deferred.then - filtering (fail)", function() {
 
 test( "jQuery.Deferred.then - filtering (progress)", function() {
 
-       expect(3);
+       expect( 3 );
 
-       var defer = jQuery.Deferred(),
+       var value1, value2, value3,
+               defer = jQuery.Deferred(),
                piped = defer.then( null, null, function( a, b ) {
                        return a * b;
-               } ),
-               value1,
-               value2,
-               value3;
+               });
 
        piped.progress(function( result ) {
                value3 = result;
@@ -191,17 +189,15 @@ test( "jQuery.Deferred.then - filtering (progress)", function() {
 
 test( "jQuery.Deferred.then - deferred (done)", function() {
 
-       expect(3);
+       expect( 3 );
 
-       var defer = jQuery.Deferred(),
+       var value1, value2, value3,
+               defer = jQuery.Deferred(),
                piped = defer.then(function( a, b ) {
                        return jQuery.Deferred(function( defer ) {
                                defer.reject( a * b );
                        });
-               }),
-               value1,
-               value2,
-               value3;
+               });
 
        piped.fail(function( result ) {
                value3 = result;
@@ -221,17 +217,15 @@ test( "jQuery.Deferred.then - deferred (done)", function() {
 
 test( "jQuery.Deferred.then - deferred (fail)", function() {
 
-       expect(3);
+       expect( 3 );
 
-       var defer = jQuery.Deferred(),
+       var value1, value2, value3,
+               defer = jQuery.Deferred(),
                piped = defer.then( null, function( a, b ) {
                        return jQuery.Deferred(function( defer ) {
                                defer.resolve( a * b );
                        });
-               } ),
-               value1,
-               value2,
-               value3;
+               });
 
        piped.done(function( result ) {
                value3 = result;
@@ -251,17 +245,15 @@ test( "jQuery.Deferred.then - deferred (fail)", function() {
 
 test( "jQuery.Deferred.then - deferred (progress)", function() {
 
-       expect(3);
+       expect( 3 );
 
-       var defer = jQuery.Deferred(),
+       var value1, value2, value3,
+               defer = jQuery.Deferred(),
                piped = defer.then( null, null, function( a, b ) {
                        return jQuery.Deferred(function( defer ) {
                                defer.resolve( a * b );
                        });
-               } ),
-               value1,
-               value2,
-               value3;
+               });
 
        piped.done(function( result ) {
                value3 = result;
@@ -281,7 +273,7 @@ test( "jQuery.Deferred.then - deferred (progress)", function() {
 
 test( "jQuery.Deferred.then - context", function() {
 
-       expect(4);
+       expect( 4 );
 
        var context = {};
 
@@ -305,12 +297,12 @@ test( "jQuery.Deferred.then - context", function() {
        });
 });
 
-test( "jQuery.when" , function() {
+test( "jQuery.when", function() {
 
        expect( 34 );
 
        // Some other objects
-       jQuery.each( {
+       jQuery.each({
 
                "an empty string": "",
                "a non-empty string": "some string",
@@ -322,19 +314,29 @@ test( "jQuery.when" , function() {
                "undefined": undefined,
                "a plain object": {}
 
-       } , function( message , value ) {
+       }, function( message, value ) {
 
-               ok( jQuery.isFunction( jQuery.when( value ).done(function( resolveValue ) {
-                       strictEqual( this, window, "Context is the global object with " + message );
-                       strictEqual( resolveValue , value , "Test the promise was resolved with " + message );
-               }).promise ) , "Test " + message + " triggers the creation of a new Promise" );
+               ok(
+                       jQuery.isFunction(
+                               jQuery.when( value ).done(function( resolveValue ) {
+                                       strictEqual( this, window, "Context is the global object with " + message );
+                                       strictEqual( resolveValue, value, "Test the promise was resolved with " + message );
+                               }).promise
+                       ),
+                       "Test " + message + " triggers the creation of a new Promise"
+               );
 
        } );
 
-       ok( jQuery.isFunction( jQuery.when().done(function( resolveValue ) {
-               strictEqual( this, window, "Test the promise was resolved with window as its context" );
-               strictEqual( resolveValue, undefined, "Test the promise was resolved with no parameter" );
-       }).promise ) , "Test calling when with no parameter triggers the creation of a new Promise" );
+       ok(
+               jQuery.isFunction(
+                       jQuery.when().done(function( resolveValue ) {
+                               strictEqual( this, window, "Test the promise was resolved with window as its context" );
+                               strictEqual( resolveValue, undefined, "Test the promise was resolved with no parameter" );
+                       }).promise
+               ),
+               "Test calling when with no parameter triggers the creation of a new Promise"
+       );
 
        var context = {};
 
@@ -344,21 +346,21 @@ test( "jQuery.when" , function() {
 
        var cache;
 
-       jQuery.each([ 1, 2, 3 ], function(k, i) {
+       jQuery.each([ 1, 2, 3 ], function( k, i ) {
 
-               jQuery.when( cache || jQuery.Deferred( function() {
+               jQuery.when( cache || jQuery.Deferred(function() {
                                this.resolve( i );
                        })
                ).done(function( value ) {
 
-                       strictEqual( value, 1 , "Function executed" + ( i > 1 ? " only once" : "" ) );
+                       strictEqual( value, 1, "Function executed" + ( i > 1 ? " only once" : "" ) );
                        cache = value;
                });
 
        });
 });
 
-test("jQuery.when - joined", function() {
+test( "jQuery.when - joined", function() {
 
        expect( 119 );
 
@@ -391,10 +393,10 @@ test("jQuery.when - joined", function() {
                                shouldError = willError[ id1 ] || willError[ id2 ],
                                shouldNotify = willNotify[ id1 ] || willNotify[ id2 ],
                                expected = shouldResolve ? [ 1, 1 ] : [ 0, undefined ],
-                                       expectedNotify = shouldNotify && [ willNotify[ id1 ], willNotify[ id2 ] ],
-                                       code = id1 + "/" + id2,
-                                       context1 = defer1 && jQuery.isFunction( defer1.promise ) ? defer1 : undefined,
-                                       context2 = defer2 && jQuery.isFunction( defer2.promise ) ? defer2 : undefined;
+                               expectedNotify = shouldNotify && [ willNotify[ id1 ], willNotify[ id2 ] ],
+                               code = id1 + "/" + id2,
+                               context1 = defer1 && jQuery.isFunction( defer1.promise ) ? defer1 : undefined,
+                               context2 = defer2 && jQuery.isFunction( defer2.promise ) ? defer2 : undefined;
 
                        jQuery.when( defer1, defer2 ).done(function( a, b ) {
                                if ( shouldResolve ) {
@@ -402,21 +404,21 @@ test("jQuery.when - joined", function() {
                                        strictEqual( this[ 0 ], context1, code + " => first context OK" );
                                        strictEqual( this[ 1 ], context2, code + " => second context OK" );
                                } else {
-                                       ok( false ,  code + " => resolve" );
+                                       ok( false,  code + " => resolve" );
                                }
                        }).fail(function( a, b ) {
                                if ( shouldError ) {
                                        deepEqual( [ a, b ], expected, code + " => reject" );
                                } else {
-                                       ok( false ,  code + " => reject" );
+                                       ok( false, code + " => reject" );
                                }
                        }).progress(function( a, b ) {
                                deepEqual( [ a, b ], expectedNotify, code + " => progress" );
                                strictEqual( this[ 0 ], expectedNotify[ 0 ] ? context1 : undefined, code + " => first context OK" );
                                strictEqual( this[ 1 ], expectedNotify[ 1 ] ? context2 : undefined, code + " => second context OK" );
                        });
-               } );
-       } );
+               });
+       });
        deferreds.futureSuccess.resolve( 1 );
        deferreds.futureError.reject( 0 );
 });