diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/csp.php | 1 | ||||
-rw-r--r-- | test/data/offset/absolute.html | 1 | ||||
-rw-r--r-- | test/data/offset/body.html | 1 | ||||
-rw-r--r-- | test/data/offset/fixed.html | 1 | ||||
-rw-r--r-- | test/data/offset/relative.html | 1 | ||||
-rw-r--r-- | test/data/offset/scroll.html | 1 | ||||
-rw-r--r-- | test/data/offset/static.html | 1 | ||||
-rw-r--r-- | test/data/offset/table.html | 1 | ||||
-rw-r--r-- | test/index.html | 2 | ||||
-rw-r--r-- | test/localfile.html | 1 | ||||
-rw-r--r-- | test/networkerror.html | 1 | ||||
-rw-r--r-- | test/readywait.html | 1 | ||||
-rw-r--r-- | test/unit/core.js | 221 | ||||
-rw-r--r-- | test/unit/deferred.js | 222 |
14 files changed, 235 insertions, 221 deletions
diff --git a/test/csp.php b/test/csp.php index acf8f32c9..13c324ea6 100644 --- a/test/csp.php +++ b/test/csp.php @@ -6,6 +6,7 @@ <title>CSP Test Page</title> <script src="../src/core.js"></script> + <script src="../src/deferred.js"></script> <script src="../src/support.js"></script> <script src="../src/data.js"></script> <script src="../src/queue.js"></script> diff --git a/test/data/offset/absolute.html b/test/data/offset/absolute.html index b4db30a6c..9d7990a37 100644 --- a/test/data/offset/absolute.html +++ b/test/data/offset/absolute.html @@ -16,6 +16,7 @@ #positionTest { position: absolute; } </style> <script src="../../../src/core.js"></script> + <script src="../../../src/deferred.js"></script> <script src="../../../src/support.js"></script> <script src="../../../src/sizzle/sizzle.js"></script> <script src="../../../src/sizzle-jquery.js"></script> diff --git a/test/data/offset/body.html b/test/data/offset/body.html index e3eb4f809..8dbf282df 100644 --- a/test/data/offset/body.html +++ b/test/data/offset/body.html @@ -9,6 +9,7 @@ #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } </style> <script src="../../../src/core.js"></script> + <script src="../../../src/deferred.js"></script> <script src="../../../src/support.js"></script> <script src="../../../src/sizzle/sizzle.js"></script> <script src="../../../src/sizzle-jquery.js"></script> diff --git a/test/data/offset/fixed.html b/test/data/offset/fixed.html index f93c20ffd..3181718da 100644 --- a/test/data/offset/fixed.html +++ b/test/data/offset/fixed.html @@ -13,6 +13,7 @@ #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } </style> <script src="../../../src/core.js"></script> + <script src="../../../src/deferred.js"></script> <script src="../../../src/support.js"></script> <script src="../../../src/sizzle/sizzle.js"></script> <script src="../../../src/sizzle-jquery.js"></script> diff --git a/test/data/offset/relative.html b/test/data/offset/relative.html index 35864760e..280a2fc0e 100644 --- a/test/data/offset/relative.html +++ b/test/data/offset/relative.html @@ -11,6 +11,7 @@ #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } </style> <script src="../../../src/core.js"></script> + <script src="../../../src/deferred.js"></script> <script src="../../../src/support.js"></script> <script src="../../../src/sizzle/sizzle.js"></script> <script src="../../../src/sizzle-jquery.js"></script> diff --git a/test/data/offset/scroll.html b/test/data/offset/scroll.html index 50de95e01..a0d1f4d18 100644 --- a/test/data/offset/scroll.html +++ b/test/data/offset/scroll.html @@ -14,6 +14,7 @@ #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } </style> <script src="../../../src/core.js"></script> + <script src="../../../src/deferred.js"></script> <script src="../../../src/support.js"></script> <script src="../../../src/sizzle/sizzle.js"></script> <script src="../../../src/sizzle-jquery.js"></script> diff --git a/test/data/offset/static.html b/test/data/offset/static.html index b1fb9f158..a61b6d10e 100644 --- a/test/data/offset/static.html +++ b/test/data/offset/static.html @@ -11,6 +11,7 @@ #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } </style> <script src="../../../src/core.js"></script> + <script src="../../../src/deferred.js"></script> <script src="../../../src/support.js"></script> <script src="../../../src/sizzle/sizzle.js"></script> <script src="../../../src/sizzle-jquery.js"></script> diff --git a/test/data/offset/table.html b/test/data/offset/table.html index 528e5303d..11fb0e795 100644 --- a/test/data/offset/table.html +++ b/test/data/offset/table.html @@ -11,6 +11,7 @@ #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } </style> <script src="../../../src/core.js"></script> + <script src="../../../src/deferred.js"></script> <script src="../../../src/support.js"></script> <script src="../../../src/sizzle/sizzle.js"></script> <script src="../../../src/sizzle-jquery.js"></script> diff --git a/test/index.html b/test/index.html index d62131530..c7c2ae55d 100644 --- a/test/index.html +++ b/test/index.html @@ -9,6 +9,7 @@ <script src="data/testinit.js"></script> <script src="../src/core.js"></script> + <script src="../src/deferred.js"></script> <script src="../src/support.js"></script> <script src="../src/data.js"></script> <script src="../src/queue.js"></script> @@ -31,6 +32,7 @@ <script src="data/testrunner.js"></script> <script src="unit/core.js"></script> + <script src="unit/deferred.js"></script> <script src="unit/data.js"></script> <script src="unit/queue.js"></script> <script src="unit/attributes.js"></script> diff --git a/test/localfile.html b/test/localfile.html index 96e0f982c..c552f2145 100644 --- a/test/localfile.html +++ b/test/localfile.html @@ -5,6 +5,7 @@ <title>jQuery Local File Test</title> <!-- Includes --> <script src="../src/core.js"></script> + <script src="../src/deferred.js"></script> <script src="../src/support.js"></script> <script src="../src/data.js"></script> <script src="../src/queue.js"></script> diff --git a/test/networkerror.html b/test/networkerror.html index b06a6ba46..f98bf4699 100644 --- a/test/networkerror.html +++ b/test/networkerror.html @@ -16,6 +16,7 @@ div { margin-top: 10px; } </style> <script src="../src/core.js"></script> + <script src="../src/deferred.js"></script> <script src="../src/support.js"></script> <script src="../src/data.js"></script> <script src="../src/queue.js"></script> diff --git a/test/readywait.html b/test/readywait.html index 8e0d3d534..4f124767a 100644 --- a/test/readywait.html +++ b/test/readywait.html @@ -15,6 +15,7 @@ #expectedOutput { background-color: green } </style> <script src="../src/core.js"></script> + <script src="../src/deferred.js"></script> <script src="../src/support.js"></script> <script src="../src/data.js"></script> <script src="../src/queue.js"></script> diff --git a/test/unit/core.js b/test/unit/core.js index 208b21c67..6ee8724de 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -914,227 +914,6 @@ test("jQuery.parseJSON", function(){ } }); -test("jQuery._Deferred()", function() { - - expect( 11 ); - - var deferred, - object, - test; - - deferred = jQuery._Deferred(); - - test = false; - - deferred.done( function( value ) { - equals( value , "value" , "Test pre-resolve callback" ); - test = true; - } ); - - deferred.resolve( "value" ); - - ok( test , "Test pre-resolve callbacks called right away" ); - - test = false; - - deferred.done( function( value ) { - equals( value , "value" , "Test post-resolve callback" ); - test = true; - } ); - - ok( test , "Test post-resolve callbacks called right away" ); - - deferred.cancel(); - - test = true; - - deferred.done( function() { - ok( false , "Cancel was ignored" ); - test = false; - } ); - - ok( test , "Test cancel" ); - - deferred = jQuery._Deferred().resolve(); - - try { - deferred.done( function() { - throw "Error"; - } , function() { - ok( true , "Test deferred do not cancel on exception" ); - } ); - } catch( e ) { - strictEqual( e , "Error" , "Test deferred propagates exceptions"); - deferred.done(); - } - - test = ""; - deferred = jQuery._Deferred().done( function() { - - test += "A"; - - }, function() { - - test += "B"; - - } ).resolve(); - - strictEqual( test , "AB" , "Test multiple done parameters" ); - - test = ""; - - deferred.done( function() { - - deferred.done( function() { - - test += "C"; - - } ); - - test += "A"; - - }, function() { - - test += "B"; - } ); - - strictEqual( test , "ABC" , "Test done callbacks order" ); - - deferred = jQuery._Deferred(); - - deferred.resolveWith( jQuery , [ document ] ).done( function( doc ) { - ok( this === jQuery && arguments.length === 1 && doc === document , "Test fire context & args" ); - }); - - // #8421 - deferred = jQuery._Deferred(); - deferred.resolveWith().done(function() { - ok( true, "Test resolveWith can be called with no argument" ); - }); -}); - -test("jQuery.Deferred()", function() { - - expect( 10 ); - - jQuery.Deferred( function( defer ) { - strictEqual( this , defer , "Defer passed as this & first argument" ); - this.resolve( "done" ); - }).then( function( value ) { - strictEqual( value , "done" , "Passed function executed" ); - }); - - jQuery.Deferred().resolve().then( function() { - ok( true , "Success on resolve" ); - }, function() { - ok( false , "Error on resolve" ); - }); - - jQuery.Deferred().reject().then( function() { - ok( false , "Success on reject" ); - }, function() { - ok( true , "Error on reject" ); - }); - - ( new jQuery.Deferred( function( defer ) { - strictEqual( this , defer , "Defer passed as this & first argument (new)" ); - this.resolve( "done" ); - }) ).then( function( value ) { - strictEqual( value , "done" , "Passed function executed (new)" ); - }); - - ( new jQuery.Deferred() ).resolve().then( function() { - ok( true , "Success on resolve (new)" ); - }, function() { - ok( false , "Error on resolve (new)" ); - }); - - ( new jQuery.Deferred() ).reject().then( function() { - ok( false , "Success on reject (new)" ); - }, function() { - ok( true , "Error on reject (new)" ); - }); - - var tmp = jQuery.Deferred(); - - strictEqual( tmp.promise() , tmp.promise() , "Test deferred always return same promise" ); - strictEqual( tmp.promise() , tmp.promise().promise() , "Test deferred's promise always return same promise as deferred" ); -}); - -test("jQuery.when()", function() { - - expect( 23 ); - - // Some other objects - jQuery.each( { - - "an empty string": "", - "a non-empty string": "some string", - "zero": 0, - "a number other than zero": 1, - "true": true, - "false": false, - "null": null, - "undefined": undefined, - "a plain object": {} - - } , function( message , value ) { - - ok( jQuery.isFunction( jQuery.when( value ).then( function( resolveValue ) { - 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().then( function( resolveValue ) { - 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 cache, i; - - for( i = 1 ; i < 4 ; i++ ) { - jQuery.when( cache || jQuery.Deferred( function() { - this.resolve( i ); - }) ).then( function( value ) { - strictEqual( value , 1 , "Function executed" + ( i > 1 ? " only once" : "" ) ); - cache = value; - }, function() { - ok( false , "Fail called" ); - }); - } -}); - -test("jQuery.when() - joined", function() { - - expect(8); - - jQuery.when( 1, 2, 3 ).done( function( a, b, c ) { - strictEqual( a , 1 , "Test first param is first resolved value - non-observables" ); - strictEqual( b , 2 , "Test second param is second resolved value - non-observables" ); - strictEqual( c , 3 , "Test third param is third resolved value - non-observables" ); - }).fail( function() { - ok( false , "Test the created deferred was resolved - non-observables"); - }); - - var successDeferred = jQuery.Deferred().resolve( 1 , 2 , 3 ), - errorDeferred = jQuery.Deferred().reject( "error" , "errorParam" ); - - jQuery.when( 1 , successDeferred , 3 ).done( function( a, b, c ) { - strictEqual( a , 1 , "Test first param is first resolved value - resolved observable" ); - same( b , [ 1 , 2 , 3 ] , "Test second param is second resolved value - resolved observable" ); - strictEqual( c , 3 , "Test third param is third resolved value - resolved observable" ); - }).fail( function() { - ok( false , "Test the created deferred was resolved - resolved observable"); - }); - - jQuery.when( 1 , errorDeferred , 3 ).done( function() { - ok( false , "Test the created deferred was rejected - rejected observable"); - }).fail( function( error , errorParam ) { - strictEqual( error , "error" , "Test first param is first rejected value - rejected observable" ); - strictEqual( errorParam , "errorParam" , "Test second param is second rejected value - rejected observable" ); - }); -}); - test("jQuery.sub() - Static Methods", function(){ expect(18); var Subclass = jQuery.sub(); diff --git a/test/unit/deferred.js b/test/unit/deferred.js new file mode 100644 index 000000000..6ba4767a6 --- /dev/null +++ b/test/unit/deferred.js @@ -0,0 +1,222 @@ +module("deferred", { teardown: moduleTeardown }); + +test("jQuery._Deferred()", function() { + + expect( 11 ); + + var deferred, + object, + test; + + deferred = jQuery._Deferred(); + + test = false; + + deferred.done( function( value ) { + equals( value , "value" , "Test pre-resolve callback" ); + test = true; + } ); + + deferred.resolve( "value" ); + + ok( test , "Test pre-resolve callbacks called right away" ); + + test = false; + + deferred.done( function( value ) { + equals( value , "value" , "Test post-resolve callback" ); + test = true; + } ); + + ok( test , "Test post-resolve callbacks called right away" ); + + deferred.cancel(); + + test = true; + + deferred.done( function() { + ok( false , "Cancel was ignored" ); + test = false; + } ); + + ok( test , "Test cancel" ); + + deferred = jQuery._Deferred().resolve(); + + try { + deferred.done( function() { + throw "Error"; + } , function() { + ok( true , "Test deferred do not cancel on exception" ); + } ); + } catch( e ) { + strictEqual( e , "Error" , "Test deferred propagates exceptions"); + deferred.done(); + } + + test = ""; + deferred = jQuery._Deferred().done( function() { + + test += "A"; + + }, function() { + + test += "B"; + + } ).resolve(); + + strictEqual( test , "AB" , "Test multiple done parameters" ); + + test = ""; + + deferred.done( function() { + + deferred.done( function() { + + test += "C"; + + } ); + + test += "A"; + + }, function() { + + test += "B"; + } ); + + strictEqual( test , "ABC" , "Test done callbacks order" ); + + deferred = jQuery._Deferred(); + + deferred.resolveWith( jQuery , [ document ] ).done( function( doc ) { + ok( this === jQuery && arguments.length === 1 && doc === document , "Test fire context & args" ); + }); + + // #8421 + deferred = jQuery._Deferred(); + deferred.resolveWith().done(function() { + ok( true, "Test resolveWith can be called with no argument" ); + }); +}); + +test("jQuery.Deferred()", function() { + + expect( 10 ); + + jQuery.Deferred( function( defer ) { + strictEqual( this , defer , "Defer passed as this & first argument" ); + this.resolve( "done" ); + }).then( function( value ) { + strictEqual( value , "done" , "Passed function executed" ); + }); + + jQuery.Deferred().resolve().then( function() { + ok( true , "Success on resolve" ); + }, function() { + ok( false , "Error on resolve" ); + }); + + jQuery.Deferred().reject().then( function() { + ok( false , "Success on reject" ); + }, function() { + ok( true , "Error on reject" ); + }); + + ( new jQuery.Deferred( function( defer ) { + strictEqual( this , defer , "Defer passed as this & first argument (new)" ); + this.resolve( "done" ); + }) ).then( function( value ) { + strictEqual( value , "done" , "Passed function executed (new)" ); + }); + + ( new jQuery.Deferred() ).resolve().then( function() { + ok( true , "Success on resolve (new)" ); + }, function() { + ok( false , "Error on resolve (new)" ); + }); + + ( new jQuery.Deferred() ).reject().then( function() { + ok( false , "Success on reject (new)" ); + }, function() { + ok( true , "Error on reject (new)" ); + }); + + var tmp = jQuery.Deferred(); + + strictEqual( tmp.promise() , tmp.promise() , "Test deferred always return same promise" ); + strictEqual( tmp.promise() , tmp.promise().promise() , "Test deferred's promise always return same promise as deferred" ); +}); + +test("jQuery.when()", function() { + + expect( 23 ); + + // Some other objects + jQuery.each( { + + "an empty string": "", + "a non-empty string": "some string", + "zero": 0, + "a number other than zero": 1, + "true": true, + "false": false, + "null": null, + "undefined": undefined, + "a plain object": {} + + } , function( message , value ) { + + ok( jQuery.isFunction( jQuery.when( value ).then( function( resolveValue ) { + 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().then( function( resolveValue ) { + 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 cache, i; + + for( i = 1 ; i < 4 ; i++ ) { + jQuery.when( cache || jQuery.Deferred( function() { + this.resolve( i ); + }) ).then( function( value ) { + strictEqual( value , 1 , "Function executed" + ( i > 1 ? " only once" : "" ) ); + cache = value; + }, function() { + ok( false , "Fail called" ); + }); + } +}); + +test("jQuery.when() - joined", function() { + + expect(8); + + jQuery.when( 1, 2, 3 ).done( function( a, b, c ) { + strictEqual( a , 1 , "Test first param is first resolved value - non-observables" ); + strictEqual( b , 2 , "Test second param is second resolved value - non-observables" ); + strictEqual( c , 3 , "Test third param is third resolved value - non-observables" ); + }).fail( function() { + ok( false , "Test the created deferred was resolved - non-observables"); + }); + + var successDeferred = jQuery.Deferred().resolve( 1 , 2 , 3 ), + errorDeferred = jQuery.Deferred().reject( "error" , "errorParam" ); + + jQuery.when( 1 , successDeferred , 3 ).done( function( a, b, c ) { + strictEqual( a , 1 , "Test first param is first resolved value - resolved observable" ); + same( b , [ 1 , 2 , 3 ] , "Test second param is second resolved value - resolved observable" ); + strictEqual( c , 3 , "Test third param is third resolved value - resolved observable" ); + }).fail( function() { + ok( false , "Test the created deferred was resolved - resolved observable"); + }); + + jQuery.when( 1 , errorDeferred , 3 ).done( function() { + ok( false , "Test the created deferred was rejected - rejected observable"); + }).fail( function( error , errorParam ) { + strictEqual( error , "error" , "Test first param is first rejected value - rejected observable" ); + strictEqual( errorParam , "errorParam" , "Test second param is second rejected value - rejected observable" ); + }); +}); |