From b930d14ce64937e9478405eee2828d4da091d2cb Mon Sep 17 00:00:00 2001 From: Oleg Gaidarenko Date: Sun, 16 Aug 2015 06:45:28 +0300 Subject: [PATCH] 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 Fixes gh-2540 --- test/data/testinit.js | 49 +- test/unit/ajax.js | 2382 ++++++++++++++++++++----------------- test/unit/animation.js | 231 ++-- test/unit/attributes.js | 982 +++++++-------- test/unit/callbacks.js | 130 +- test/unit/core.js | 1072 ++++++++--------- test/unit/css.js | 569 ++++----- test/unit/data.js | 517 ++++---- test/unit/deferred.js | 196 +-- test/unit/deprecated.js | 2 +- test/unit/dimensions.js | 356 +++--- test/unit/effects.js | 905 +++++++------- test/unit/event.js | 1160 +++++++++--------- test/unit/exports.js | 8 +- test/unit/manipulation.js | 1342 ++++++++++----------- test/unit/offset.js | 322 ++--- test/unit/queue.js | 180 +-- test/unit/ready.js | 30 +- test/unit/selector.js | 340 +++--- test/unit/serialize.js | 78 +- test/unit/support.js | 45 +- test/unit/traversing.js | 816 ++++++------- test/unit/tween.js | 203 ++-- test/unit/wrap.js | 224 ++-- 24 files changed, 6198 insertions(+), 5941 deletions(-) diff --git a/test/data/testinit.js b/test/data/testinit.js index ef90fe45c..0dcb4f871 100644 --- a/test/data/testinit.js +++ b/test/data/testinit.js @@ -137,16 +137,20 @@ function url( value ) { // Ajax testing helper this.ajaxTest = function( title, expect, options ) { - var requestOptions; - if ( jQuery.isFunction( options ) ) { - options = options(); - } - options = options || []; - requestOptions = options.requests || options.request || options; - if ( !jQuery.isArray( requestOptions ) ) { - requestOptions = [ requestOptions ]; - } - asyncTest( title, expect, function() { + QUnit.test( title, expect, function( assert ) { + var requestOptions; + + if ( jQuery.isFunction( options ) ) { + options = options( assert ); + } + options = options || []; + requestOptions = options.requests || options.request || options; + if ( !jQuery.isArray( requestOptions ) ) { + requestOptions = [ requestOptions ]; + } + + var done = assert.async(); + if ( options.setup ) { options.setup(); } @@ -160,7 +164,9 @@ this.ajaxTest = function( title, expect, options ) { if ( options.teardown ) { options.teardown(); } - start(); + + // Make sure all events will be called before done() + setTimeout(done); } }, requests = jQuery.map( requestOptions, function( options ) { @@ -170,7 +176,7 @@ this.ajaxTest = function( title, expect, options ) { return function( _, status ) { if ( !completed ) { if ( !handler ) { - ok( false, "unexpected " + status ); + assert.ok( false, "unexpected " + status ); } else if ( jQuery.isFunction( handler ) ) { handler.apply( this, arguments ); } @@ -179,7 +185,7 @@ this.ajaxTest = function( title, expect, options ) { }; if ( options.afterSend ) { - options.afterSend( request ); + options.afterSend( request, assert ); } return request @@ -202,7 +208,8 @@ this.ajaxTest = function( title, expect, options ) { }; this.testIframe = function( fileName, name, fn ) { - asyncTest(name, function() { + QUnit.test(name, function( assert ) { + var done = assert.async(); // load fixture in iframe var iframe = loadFixture(), @@ -211,10 +218,9 @@ this.testIframe = function( fileName, name, fn ) { if ( win && win.jQuery && win.jQuery.isReady ) { clearInterval( interval ); - start(); - // call actual tests passing the correct jQuery instance to use - fn.call( this, win.jQuery, win, win.document ); + fn.call( this, win.jQuery, win, win.document, assert ); + done(); document.body.removeChild( iframe ); iframe = null; } @@ -233,11 +239,14 @@ this.testIframe = function( fileName, name, fn ) { }; this.testIframeWithCallback = function( title, fileName, func ) { - asyncTest( title, 1, function() { + QUnit.test( title, 1, function( assert ) { var iframe; + var done = assert.async(); window.iframeCallback = function() { - var args = arguments; + var args = Array.prototype.slice.call( arguments ); + + args.push( assert ); setTimeout(function() { this.iframeCallback = undefined; @@ -246,7 +255,7 @@ this.testIframeWithCallback = function( title, fileName, func ) { func.apply( this, args ); func = function() {}; - start(); + done(); }); }; iframe = jQuery( "
" ).css({ position: "absolute", width: "500px", left: "-600px" }) diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 6eedc5784..2f8334147 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -1,4 +1,4 @@ -module( "ajax", { +QUnit.module( "ajax", { teardown: function() { jQuery( document ).off( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess" ); moduleTeardown.apply( this, arguments ); @@ -6,122 +6,136 @@ module( "ajax", { }); (function() { - test("Unit Testing Environment", function () { - expect( 2 ); + QUnit.test("Unit Testing Environment", function( assert ) { + assert.expect( 2 ); - ok( hasPHP, "Running in an environment with PHP support. The AJAX tests only run if the environment supports PHP!" ); - ok( !isLocal, "Unit tests are not ran from file:// (especially in Chrome. If you must test from file:// with Chrome, run it with the --allow-file-access-from-files flag!)" ); + assert.ok( hasPHP, "Running in an environment with PHP support. The AJAX tests only run if the environment supports PHP!" ); + assert.ok( !isLocal, "Unit tests are not ran from file:// (especially in Chrome. If you must test from file:// with Chrome, run it with the --allow-file-access-from-files flag!)" ); }); if ( !jQuery.ajax || ( isLocal && !hasPHP ) ) { return; } - function addGlobalEvents( expected ) { + function addGlobalEvents( expected, assert ) { return function() { expected = expected || ""; jQuery( document ).on( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess", function( e ) { - ok( expected.indexOf(e.type) !== -1, e.type ); + assert.ok( expected.indexOf(e.type) !== -1, e.type ); }); }; } //----------- jQuery.ajax() - testIframeWithCallback( "XMLHttpRequest - Attempt to block tests because of dangling XHR requests (IE)", "ajax/unreleasedXHR.html", function() { - expect( 1 ); - ok( true, "done" ); - }); - - ajaxTest( "jQuery.ajax() - success callbacks", 8, { - setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"), - url: url("data/name.html"), - beforeSend: function() { - ok( true, "beforeSend" ); - }, - success: function() { - ok( true, "success" ); - }, - complete: function() { - ok( true, "complete"); + testIframeWithCallback( + "XMLHttpRequest - Attempt to block tests because of dangling XHR requests (IE)", + "ajax/unreleasedXHR.html", + function( assert ) { + assert.expect( 1 ); + assert.ok( true, "done" ); } + ); + + ajaxTest( "jQuery.ajax() - success callbacks", 8, function( assert ) { + return { + setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ), + url: url("data/name.html"), + beforeSend: function() { + assert.ok( true, "beforeSend" ); + }, + success: function() { + assert.ok( true, "success" ); + }, + complete: function() { + assert.ok( true, "complete"); + } + }; }); - ajaxTest( "jQuery.ajax() - success callbacks - (url, options) syntax", 8, { - setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"), - create: function( options ) { - return jQuery.ajax( url("data/name.html"), options ); - }, - beforeSend: function() { - ok( true, "beforeSend" ); - }, - success: function() { - ok( true, "success" ); - }, - complete: function() { - ok( true, "complete" ); - } + ajaxTest( "jQuery.ajax() - success callbacks - (url, options) syntax", 8, function( assert ) { + return { + setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ), + create: function( options ) { + return jQuery.ajax( url("data/name.html"), options ); + }, + beforeSend: function() { + assert.ok( true, "beforeSend" ); + }, + success: function() { + assert.ok( true, "success" ); + }, + complete: function() { + assert.ok( true, "complete" ); + } + }; }); - ajaxTest( "jQuery.ajax() - success callbacks (late binding)", 8, { - setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"), - url: url("data/name.html"), - beforeSend: function() { - ok( true, "beforeSend" ); - }, - success: true, - afterSend: function( request ) { - request.always(function() { - ok( true, "complete" ); - }).done(function() { - ok( true, "success" ); - }).fail(function() { - ok( false, "error" ); - }); - } + ajaxTest( "jQuery.ajax() - success callbacks (late binding)", 8, function( assert ) { + return { + setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ), + url: url("data/name.html"), + beforeSend: function() { + assert.ok( true, "beforeSend" ); + }, + success: true, + afterSend: function( request ) { + request.always(function() { + assert.ok( true, "complete" ); + }).done(function() { + assert.ok( true, "success" ); + }).fail(function() { + assert.ok( false, "error" ); + }); + } + }; }); - ajaxTest( "jQuery.ajax() - success callbacks (oncomplete binding)", 8, { - setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess"), - url: url("data/name.html"), - beforeSend: function() { - ok( true, "beforeSend" ); - }, - success: true, - complete: function( xhr ) { - xhr.always(function() { - ok( true, "complete" ); - }).done(function() { - ok( true, "success" ); - }).fail(function() { - ok( false, "error" ); - }); - } + ajaxTest( "jQuery.ajax() - success callbacks (oncomplete binding)", 8, function( assert ) { + return { + setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ), + url: url("data/name.html"), + beforeSend: function() { + assert.ok( true, "beforeSend" ); + }, + success: true, + complete: function( xhr ) { + xhr.always(function() { + assert.ok( true, "complete" ); + }).done(function() { + assert.ok( true, "success" ); + }).fail(function() { + assert.ok( false, "error" ); + }); + } + }; }); - ajaxTest( "jQuery.ajax() - error callbacks", 8, { - setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError"), - url: url("data/name.php?wait=5"), - beforeSend: function() { - ok( true, "beforeSend" ); - }, - afterSend: function( request ) { - request.abort(); - }, - error: function() { - ok( true, "error" ); - }, - complete: function() { - ok( true, "complete" ); - } + ajaxTest( "jQuery.ajax() - error callbacks", 8, function( assert ) { + return { + setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError", assert ), + url: url("data/name.php?wait=5"), + beforeSend: function() { + assert.ok( true, "beforeSend" ); + }, + afterSend: function( request ) { + request.abort(); + }, + error: function() { + assert.ok( true, "error" ); + }, + complete: function() { + assert.ok( true, "complete" ); + } + }; }); - ajaxTest( "jQuery.ajax() - textStatus and errorThrown values", 4, [ - { + ajaxTest( "jQuery.ajax() - textStatus and errorThrown values", 4, function( assert ) { + return [{ url: url("data/name.php?wait=5"), error: function( _, textStatus, errorThrown ) { - strictEqual( textStatus, "abort", "textStatus is 'abort' for abort" ); - strictEqual( errorThrown, "abort", "errorThrown is 'abort' for abort" ); + assert.strictEqual( textStatus, "abort", "textStatus is 'abort' for abort" ); + assert.strictEqual( errorThrown, "abort", "errorThrown is 'abort' for abort" ); }, afterSend: function( request ) { request.abort(); @@ -130,23 +144,25 @@ module( "ajax", { { url: url("data/name.php?wait=5"), error: function( _, textStatus, errorThrown ) { - strictEqual( textStatus, "mystatus", "textStatus is 'mystatus' for abort('mystatus')" ); - strictEqual( errorThrown, "mystatus", "errorThrown is 'mystatus' for abort('mystatus')" ); + assert.strictEqual( textStatus, "mystatus", "textStatus is 'mystatus' for abort('mystatus')" ); + assert.strictEqual( errorThrown, "mystatus", "errorThrown is 'mystatus' for abort('mystatus')" ); }, afterSend: function( request ) { request.abort("mystatus"); } - } - ]); + }]; + }); - ajaxTest( "jQuery.ajax() - responseText on error", 1, { - url: url("data/errorWithText.php"), - error: function( xhr ) { - strictEqual( xhr.responseText, "plain text message", "Test jqXHR.responseText is filled for HTTP errors" ); - } + ajaxTest( "jQuery.ajax() - responseText on error", 1, function( assert ) { + return { + url: url("data/errorWithText.php"), + error: function( xhr ) { + assert.strictEqual( xhr.responseText, "plain text message", "Test jqXHR.responseText is filled for HTTP errors" ); + } + }; }); - asyncTest( "jQuery.ajax() - retry with jQuery.ajax( this )", 2, function() { + QUnit.asyncTest( "jQuery.ajax() - retry with jQuery.ajax( this )", 2, function( assert ) { var previousUrl, firstTime = true; jQuery.ajax({ @@ -166,8 +182,8 @@ module( "ajax", { if ( !previousUrl ) { previousUrl = this.url; } else { - strictEqual( this.url, previousUrl, "url parameters are not re-appended" ); - start(); + assert.strictEqual( this.url, previousUrl, "url parameters are not re-appended" ); + QUnit.start(); return false; } }, @@ -180,128 +196,138 @@ module( "ajax", { }); }); - ajaxTest( "jQuery.ajax() - headers", 5, { - setup: function() { - jQuery( document ).ajaxSend(function( evt, xhr ) { - xhr.setRequestHeader( "ajax-send", "test" ); - }); - }, - url: url("data/headers.php?keys=siMPle_SometHing-elsE_OthEr_Nullable_undefined_Empty_ajax-send"), - headers: { - "siMPle": "value", - "SometHing-elsE": "other value", - "OthEr": "something else", - "Nullable": null, - "undefined": undefined - - // Support: Firefox - // Not all browsers allow empty-string headers - // https://bugzilla.mozilla.org/show_bug.cgi?id=815299 - //"Empty": "" - }, - success: function( data, _, xhr ) { - var i, emptyHeader, - requestHeaders = jQuery.extend( this.headers, { - "ajax-send": "test" - }), - tmp = []; - for ( i in requestHeaders ) { - tmp.push( i, ": ", requestHeaders[ i ] + "", "\n" ); - } - tmp = tmp.join(""); + ajaxTest( "jQuery.ajax() - headers", 5, function( assert ) { + return { + setup: function() { + jQuery( document ).ajaxSend(function( evt, xhr ) { + xhr.setRequestHeader( "ajax-send", "test" ); + }); + }, + url: url("data/headers.php?keys=siMPle_SometHing-elsE_OthEr_Nullable_undefined_Empty_ajax-send"), + headers: { + "siMPle": "value", + "SometHing-elsE": "other value", + "OthEr": "something else", + "Nullable": null, + "undefined": undefined + + // Support: Firefox + // Not all browsers allow empty-string headers + // https://bugzilla.mozilla.org/show_bug.cgi?id=815299 + //"Empty": "" + }, + success: function( data, _, xhr ) { + var i, emptyHeader, + requestHeaders = jQuery.extend( this.headers, { + "ajax-send": "test" + }), + tmp = []; + for ( i in requestHeaders ) { + tmp.push( i, ": ", requestHeaders[ i ] + "", "\n" ); + } + tmp = tmp.join(""); - strictEqual( data, tmp, "Headers were sent" ); - strictEqual( xhr.getResponseHeader("Sample-Header"), "Hello World", "Sample header received" ); - ok( data.indexOf( "undefined" ) < 0 , "Undefined header value was not sent" ); + assert.strictEqual( data, tmp, "Headers were sent" ); + assert.strictEqual( xhr.getResponseHeader("Sample-Header"), "Hello World", "Sample header received" ); + assert.ok( data.indexOf( "undefined" ) < 0 , "Undefined header value was not sent" ); - emptyHeader = xhr.getResponseHeader("Empty-Header"); - if ( emptyHeader === null ) { - ok( true, "Firefox doesn't support empty headers" ); - } else { - strictEqual( emptyHeader, "", "Empty header received" ); + emptyHeader = xhr.getResponseHeader("Empty-Header"); + if ( emptyHeader === null ) { + assert.ok( true, "Firefox doesn't support empty headers" ); + } else { + assert.strictEqual( emptyHeader, "", "Empty header received" ); + } + assert.strictEqual( xhr.getResponseHeader("Sample-Header2"), "Hello World 2", "Second sample header received" ); } - strictEqual( xhr.getResponseHeader("Sample-Header2"), "Hello World 2", "Second sample header received" ); - } - }); - - ajaxTest( "jQuery.ajax() - Accept header", 1, { - url: url("data/headers.php?keys=accept"), - headers: { - Accept: "very wrong accept value" - }, - beforeSend: function( xhr ) { - xhr.setRequestHeader("Accept", "*/*"); - }, - success: function( data ) { - strictEqual( data, "accept: */*\n", "Test Accept header is set to last value provided" ); - } + }; }); - ajaxTest( "jQuery.ajax() - contentType", 2, [ - { - url: url("data/headers.php?keys=content-type"), - contentType: "test", - success: function( data ) { - strictEqual( data, "content-type: test\n", "Test content-type is sent when options.contentType is set" ); - } - }, - { - url: url("data/headers.php?keys=content-type"), - contentType: false, + ajaxTest( "jQuery.ajax() - Accept header", 1, function( assert ) { + return { + url: url("data/headers.php?keys=accept"), + headers: { + Accept: "very wrong accept value" + }, + beforeSend: function( xhr ) { + xhr.setRequestHeader("Accept", "*/*"); + }, success: function( data ) { - // Some server/interpreter combinations always supply a Content-Type to scripts - data = data || "content-type: \n"; - strictEqual( data, "content-type: \n", "Test content-type is not set when options.contentType===false" ); + assert.strictEqual( data, "accept: */*\n", "Test Accept header is set to last value provided" ); } - } - ]); - - ajaxTest( "jQuery.ajax() - protocol-less urls", 1, { - url: "//somedomain.com", - beforeSend: function( xhr, settings ) { - equal( settings.url, location.protocol + "//somedomain.com", "Make sure that the protocol is added." ); - return false; - }, - error: true + }; }); - ajaxTest( "jQuery.ajax() - hash", 3, [ - { - url: "data/name.html#foo", - beforeSend: function( xhr, settings ) { - equal( settings.url, "data/name.html", "Make sure that the URL is trimmed." ); - return false; + ajaxTest( "jQuery.ajax() - contentType", 2, function( assert ) { + return [ + { + url: url("data/headers.php?keys=content-type"), + contentType: "test", + success: function( data ) { + assert.strictEqual( data, "content-type: test\n", "Test content-type is sent when options.contentType is set" ); + } }, - error: true - }, - { - url: "data/name.html?abc#foo", + { + url: url("data/headers.php?keys=content-type"), + contentType: false, + success: function( data ) { + // Some server/interpreter combinations always supply a Content-Type to scripts + data = data || "content-type: \n"; + assert.strictEqual( data, "content-type: \n", "Test content-type is not set when options.contentType===false" ); + } + } + ]; + }); + + ajaxTest( "jQuery.ajax() - protocol-less urls", 1, function( assert ) { + return { + url: "//somedomain.com", beforeSend: function( xhr, settings ) { - equal( settings.url, "data/name.html?abc", "Make sure that the URL is trimmed." ); + assert.equal( settings.url, location.protocol + "//somedomain.com", "Make sure that the protocol is added." ); return false; }, error: true - }, - { - url: "data/name.html?abc#foo", - data: { - "test": 123 + }; + }); + + ajaxTest( "jQuery.ajax() - hash", 3, function( assert ) { + return [ + { + url: "data/name.html#foo", + beforeSend: function( xhr, settings ) { + assert.equal( settings.url, "data/name.html", "Make sure that the URL is trimmed." ); + return false; + }, + error: true }, - beforeSend: function( xhr, settings ) { - equal( settings.url, "data/name.html?abc&test=123", "Make sure that the URL is trimmed." ); - return false; + { + url: "data/name.html?abc#foo", + beforeSend: function( xhr, settings ) { + assert.equal( settings.url, "data/name.html?abc", "Make sure that the URL is trimmed." ); + return false; + }, + error: true }, - error: true - } - ]); + { + url: "data/name.html?abc#foo", + data: { + "test": 123 + }, + beforeSend: function( xhr, settings ) { + assert.equal( settings.url, "data/name.html?abc&test=123", "Make sure that the URL is trimmed." ); + return false; + }, + error: true + } + ]; + }); - ajaxTest( "jQuery.ajax() - cross-domain detection", 8, function() { + ajaxTest( "jQuery.ajax() - cross-domain detection", 8, function( assert ) { function request( url, title, crossDomainOrOptions ) { return jQuery.extend( { dataType: "jsonp", url: url, beforeSend: function( _, s ) { - ok( crossDomainOrOptions === false ? !s.crossDomain : s.crossDomain, title ); + assert.ok( crossDomainOrOptions === false ? !s.crossDomain : s.crossDomain, title ); return false; }, error: true @@ -353,34 +379,35 @@ module( "ajax", { ]; }); - ajaxTest( "jQuery.ajax() - abort", 9, { - setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxError ajaxComplete"), - url: url("data/name.php?wait=5"), - beforeSend: function() { - ok( true, "beforeSend" ); - }, - afterSend: function( xhr ) { - strictEqual( xhr.readyState, 1, "XHR readyState indicates successful dispatch" ); - xhr.abort(); - strictEqual( xhr.readyState, 0, "XHR readyState indicates successful abortion" ); - }, - error: true, - complete: function() { - ok( true, "complete" ); - } + ajaxTest( "jQuery.ajax() - abort", 9, function( assert ) { + return { + setup: addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxError ajaxComplete", assert ), + url: url("data/name.php?wait=5"), + beforeSend: function() { + assert.ok( true, "beforeSend" ); + }, + afterSend: function( xhr ) { + assert.strictEqual( xhr.readyState, 1, "XHR readyState indicates successful dispatch" ); + xhr.abort(); + assert.strictEqual( xhr.readyState, 0, "XHR readyState indicates successful abortion" ); + }, + error: true, + complete: function() { + assert.ok( true, "complete" ); + } + }; }); - ajaxTest( "jQuery.ajax() - events with context", 12, function() { - + ajaxTest( "jQuery.ajax() - events with context", 12, function( assert ) { var context = document.createElement("div"); function event( e ) { - equal( this, context, e.type ); + assert.equal( this, context, e.type ); } function callback( msg ) { return function() { - equal( this, context, "context is preserved on callback " + msg ); + assert.equal( this, context, "context is preserved on callback " + msg ); }; } @@ -408,10 +435,10 @@ module( "ajax", { }; }); - ajaxTest( "jQuery.ajax() - events without context", 3, function() { + ajaxTest( "jQuery.ajax() - events without context", 3, function( assert ) { function nocallback( msg ) { return function() { - equal( typeof this.url, "string", "context is settings on callback " + msg ); + assert.equal( typeof this.url, "string", "context is settings on callback " + msg ); }; } return { @@ -422,7 +449,7 @@ module( "ajax", { }; }); - ajaxTest( "#15118 - jQuery.ajax() - function without jQuery.event", 1, function() { + ajaxTest( "#15118 - jQuery.ajax() - function without jQuery.event", 1, function( assert ) { var holder; return { url: url( "data/json.php" ), @@ -431,200 +458,222 @@ module( "ajax", { delete jQuery.event; }, complete: function() { - ok( true, "Call can be made without jQuery.event" ); + assert.ok( true, "Call can be made without jQuery.event" ); jQuery.event = holder; }, success: true }; }); - ajaxTest( "#15160 - jQuery.ajax() - request manually aborted in ajaxSend", 3, { - setup: function() { - jQuery( document ).on( "ajaxSend", function( e, jqXHR ) { - jqXHR.abort(); - }); + ajaxTest( "#15160 - jQuery.ajax() - request manually aborted in ajaxSend", 3, function( assert ) { + return { + setup: function() { + jQuery( document ).on( "ajaxSend", function( e, jqXHR ) { + jqXHR.abort(); + }); - jQuery( document ).on( "ajaxError ajaxComplete", function( e, jqXHR ) { - equal( jqXHR.statusText, "abort", "jqXHR.statusText equals abort on global ajaxComplete and ajaxError events" ); - }); - }, - url: url("data/name.html"), - error: true, - complete: function() { - ok( true, "complete" ); - } + jQuery( document ).on( "ajaxError ajaxComplete", function( e, jqXHR ) { + assert.equal( jqXHR.statusText, "abort", "jqXHR.statusText equals abort on global ajaxComplete and ajaxError events" ); + }); + }, + url: url("data/name.html"), + error: true, + complete: function() { + assert.ok( true, "complete" ); + } + }; }); - ajaxTest( "jQuery.ajax() - context modification", 1, { - url: url("data/name.html"), - context: {}, - beforeSend: function() { - this.test = "foo"; - }, - afterSend: function() { - strictEqual( this.context.test, "foo", "Make sure the original object is maintained." ); - }, - success: true + ajaxTest( "jQuery.ajax() - context modification", 1, function( assert ) { + return { + url: url("data/name.html"), + context: {}, + beforeSend: function() { + this.test = "foo"; + }, + afterSend: function() { + assert.strictEqual( this.context.test, "foo", "Make sure the original object is maintained." ); + }, + success: true + }; }); - ajaxTest( "jQuery.ajax() - context modification through ajaxSetup", 3, function() { + ajaxTest( "jQuery.ajax() - context modification through ajaxSetup", 3, function( assert ) { var obj = {}; return { setup: function() { jQuery.ajaxSetup({ context: obj }); - strictEqual( jQuery.ajaxSettings.context, obj, "Make sure the context is properly set in ajaxSettings." ); + assert.strictEqual( jQuery.ajaxSettings.context, obj, "Make sure the context is properly set in ajaxSettings." ); }, requests: [{ url: url("data/name.html"), success: function() { - strictEqual( this, obj, "Make sure the original object is maintained." ); + assert.strictEqual( this, obj, "Make sure the original object is maintained." ); } }, { url: url("data/name.html"), context: {}, success: function() { - ok( this !== obj, "Make sure overriding context is possible." ); + assert.ok( this !== obj, "Make sure overriding context is possible." ); } }] }; }); - ajaxTest( "jQuery.ajax() - disabled globals", 3, { - setup: addGlobalEvents(""), - global: false, - url: url("data/name.html"), - beforeSend: function() { - ok( true, "beforeSend" ); - }, - success: function() { - ok( true, "success" ); - }, - complete: function() { - ok( true, "complete" ); - } - }); - - ajaxTest( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements", 3, { - url: url("data/with_fries.xml"), - dataType: "xml", - success: function( resp ) { - equal( jQuery( "properties", resp ).length, 1, "properties in responseXML" ); - equal( jQuery( "jsconf", resp ).length, 1, "jsconf in responseXML" ); - equal( jQuery( "thing", resp ).length, 2, "things in responseXML" ); - } + ajaxTest( "jQuery.ajax() - disabled globals", 3, function( assert ) { + return { + setup: addGlobalEvents( "", assert ), + global: false, + url: url("data/name.html"), + beforeSend: function() { + assert.ok( true, "beforeSend" ); + }, + success: function() { + assert.ok( true, "success" ); + }, + complete: function() { + assert.ok( true, "complete" ); + } + }; }); - ajaxTest( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements (over JSONP)", 3, { - url: url("data/with_fries_over_jsonp.php"), - dataType: "jsonp xml", - success: function( resp ) { - equal( jQuery( "properties", resp ).length, 1, "properties in responseXML" ); - equal( jQuery( "jsconf", resp ).length, 1, "jsconf in responseXML" ); - equal( jQuery( "thing", resp ).length, 2, "things in responseXML" ); - } + ajaxTest( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements", 3, function( assert ) { + return { + url: url("data/with_fries.xml"), + dataType: "xml", + success: function( resp ) { + assert.equal( jQuery( "properties", resp ).length, 1, "properties in responseXML" ); + assert.equal( jQuery( "jsconf", resp ).length, 1, "jsconf in responseXML" ); + assert.equal( jQuery( "thing", resp ).length, 2, "things in responseXML" ); + } + }; }); - ajaxTest( "jQuery.ajax() - HEAD requests", 2, [ - { - url: url("data/name.html"), - type: "HEAD", - success: function( data, status, xhr ) { - ok( /Date/i.test( xhr.getAllResponseHeaders() ), "No Date in HEAD response" ); - } - }, - { - url: url("data/name.html"), - data: { - "whip_it": "good" - }, - type: "HEAD", - success: function( data, status, xhr ) { - ok( /Date/i.test( xhr.getAllResponseHeaders() ), "No Date in HEAD response with data" ); + ajaxTest( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements (over JSONP)", 3, function( assert ) { + return { + url: url("data/with_fries_over_jsonp.php"), + dataType: "jsonp xml", + success: function( resp ) { + assert.equal( jQuery( "properties", resp ).length, 1, "properties in responseXML" ); + assert.equal( jQuery( "jsconf", resp ).length, 1, "jsconf in responseXML" ); + assert.equal( jQuery( "thing", resp ).length, 2, "things in responseXML" ); } - } - ]); - - ajaxTest( "jQuery.ajax() - beforeSend", 1, { - url: url("data/name.html"), - beforeSend: function() { - this.check = true; - }, - success: function() { - ok( this.check, "check beforeSend was executed" ); - } + }; }); - ajaxTest( "jQuery.ajax() - beforeSend, cancel request manually", 2, { - create: function() { - return jQuery.ajax({ + ajaxTest( "jQuery.ajax() - HEAD requests", 2, function( assert ) { + return [ + { url: url("data/name.html"), - beforeSend: function( xhr ) { - ok( true, "beforeSend got called, canceling" ); - xhr.abort(); - }, - success: function() { - ok( false, "request didn't get canceled" ); - }, - complete: function() { - ok( false, "request didn't get canceled" ); + type: "HEAD", + success: function( data, status, xhr ) { + assert.ok( /Date/i.test( xhr.getAllResponseHeaders() ), "No Date in HEAD response" ); + } + }, + { + url: url("data/name.html"), + data: { + "whip_it": "good" }, - error: function() { - ok( false, "request didn't get canceled" ); + type: "HEAD", + success: function( data, status, xhr ) { + assert.ok( /Date/i.test( xhr.getAllResponseHeaders() ), "No Date in HEAD response with data" ); } - }); - }, - fail: function( _, reason ) { - strictEqual( reason, "canceled", "canceled request must fail with 'canceled' status text" ); - } - }); - - ajaxTest( "jQuery.ajax() - dataType html", 5, { - setup: function() { - Globals.register("testFoo"); - Globals.register("testBar"); - }, - dataType: "html", - url: url("data/test.html"), - success: function( data ) { - ok( data.match( /^html text/ ), "Check content for datatype html" ); - jQuery("#ap").html( data ); - strictEqual( window["testFoo"], "foo", "Check if script was evaluated for datatype html" ); - strictEqual( window["testBar"], "bar", "Check if script src was evaluated for datatype html" ); - } - }); - - ajaxTest( "jQuery.ajax() - synchronous request", 1, { - url: url("data/json_obj.js"), - dataType: "text", - async: false, - success: true, - afterSend: function( xhr ) { - ok( /^\{ "data"/.test( xhr.responseText ), "check returned text" ); - } + } + ]; }); - ajaxTest( "jQuery.ajax() - synchronous request with callbacks", 2, { - url: url("data/json_obj.js"), - async: false, - dataType: "text", - success: true, - afterSend: function( xhr ) { - var result; - xhr.done(function( data ) { - ok( true, "success callback executed" ); - result = data; - }); - ok( /^\{ "data"/.test( result ), "check returned text" ); - } + ajaxTest( "jQuery.ajax() - beforeSend", 1, function( assert ) { + return { + url: url("data/name.html"), + beforeSend: function() { + this.check = true; + }, + success: function() { + assert.ok( this.check, "check beforeSend was executed" ); + } + }; }); - asyncTest( "jQuery.ajax(), jQuery.get[Script|JSON](), jQuery.post(), pass-through request object", 8, function() { - var target = "data/name.html", - successCount = 0, - errorCount = 0, - errorEx = "", + ajaxTest( "jQuery.ajax() - beforeSend, cancel request manually", 2, function( assert ) { + return { + create: function() { + return jQuery.ajax({ + url: url("data/name.html"), + beforeSend: function( xhr ) { + assert.ok( true, "beforeSend got called, canceling" ); + xhr.abort(); + }, + success: function() { + assert.ok( false, "request didn't get canceled" ); + }, + complete: function() { + assert.ok( false, "request didn't get canceled" ); + }, + error: function() { + assert.ok( false, "request didn't get canceled" ); + } + }); + }, + fail: function( _, reason ) { + assert.strictEqual( reason, "canceled", "canceled request must fail with 'canceled' status text" ); + } + }; + }); + + ajaxTest( "jQuery.ajax() - dataType html", 5, function( assert ) { + return { + setup: function() { + Globals.register("testFoo"); + Globals.register("testBar"); + }, + dataType: "html", + url: url("data/test.html"), + success: function( data ) { + assert.ok( data.match( /^html text/ ), "Check content for datatype html" ); + jQuery("#ap").html( data ); + assert.strictEqual( window["testFoo"], "foo", "Check if script was evaluated for datatype html" ); + assert.strictEqual( window["testBar"], "bar", "Check if script src was evaluated for datatype html" ); + } + }; + }); + + ajaxTest( "jQuery.ajax() - synchronous request", 1, function( assert ) { + return { + url: url("data/json_obj.js"), + dataType: "text", + async: false, + success: true, + afterSend: function( xhr ) { + assert.ok( /^\{ "data"/.test( xhr.responseText ), "check returned text" ); + } + }; + }); + + ajaxTest( "jQuery.ajax() - synchronous request with callbacks", 2, function( assert ) { + return { + url: url("data/json_obj.js"), + async: false, + dataType: "text", + success: true, + afterSend: function( xhr ) { + var result; + xhr.done(function( data ) { + assert.ok( true, "success callback executed" ); + result = data; + }); + assert.ok( /^\{ "data"/.test( result ), "check returned text" ); + } + }; + }); + + QUnit.asyncTest( "jQuery.ajax(), jQuery.get[Script|JSON](), jQuery.post(), pass-through request object", 8, function( assert ) { + var target = "data/name.html", + successCount = 0, + errorCount = 0, + errorEx = "", success = function() { successCount++; }; @@ -633,25 +682,24 @@ module( "ajax", { errorEx += ": " + xml.status; }); jQuery( document ).one( "ajaxStop", function() { - equal( successCount, 5, "Check all ajax calls successful" ); - equal( errorCount, 0, "Check no ajax errors (status" + errorEx + ")" ); + assert.equal( successCount, 5, "Check all ajax calls successful" ); + assert.equal( errorCount, 0, "Check no ajax errors (status" + errorEx + ")" ); jQuery( document ).off("ajaxError.passthru"); - start(); + QUnit.start(); }); Globals.register("testBar"); - ok( jQuery.get( url(target), success ), "get" ); - ok( jQuery.post( url(target), success ), "post" ); - ok( jQuery.getScript( url("data/testbar.php"), success ), "script" ); - ok( jQuery.getJSON( url("data/json_obj.js"), success ), "json" ); - ok( jQuery.ajax({ + assert.ok( jQuery.get( url(target), success ), "get" ); + assert.ok( jQuery.post( url(target), success ), "post" ); + assert.ok( jQuery.getScript( url("data/testbar.php"), success ), "script" ); + assert.ok( jQuery.getJSON( url("data/json_obj.js"), success ), "json" ); + assert.ok( jQuery.ajax({ url: url( target ), success: success }), "generic" ); }); - ajaxTest( "jQuery.ajax() - cache", 12, function() { - + ajaxTest( "jQuery.ajax() - cache", 12, function( assert ) { var re = /_=(.*?)(&|$)/g; function request( url, title ) { @@ -661,9 +709,9 @@ module( "ajax", { beforeSend: function() { var parameter, tmp; while(( tmp = re.exec( this.url ) )) { - strictEqual( parameter, undefined, title + ": only one 'no-cache' parameter" ); + assert.strictEqual( parameter, undefined, title + ": only one 'no-cache' parameter" ); parameter = tmp[ 1 ]; - notStrictEqual( parameter, "tobereplaced555", title + ": parameter (if it was there) was replaced" ); + assert.notStrictEqual( parameter, "tobereplaced555", title + ": parameter (if it was there) was replaced" ); } return false; }, @@ -701,316 +749,346 @@ module( "ajax", { jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) { - ajaxTest( "jQuery.ajax() - JSONP - Query String (?n)" + label, 4, [ - { - url: "data/jsonp.php?callback=?", - dataType: "jsonp", - crossDomain: crossDomain, - success: function( data ) { - ok( data.data, "JSON results returned (GET, url callback)" ); - } - }, - { - url: "data/jsonp.php?callback=??", - dataType: "jsonp", - crossDomain: crossDomain, - success: function( data ) { - ok( data.data, "JSON results returned (GET, url context-free callback)" ); - } - }, - { - url: "data/jsonp.php/??", - dataType: "jsonp", - crossDomain: crossDomain, - success: function( data ) { - ok( data.data, "JSON results returned (GET, REST-like)" ); - } - }, - { - url: "data/jsonp.php/???json=1", - dataType: "jsonp", - crossDomain: crossDomain, - success: function( data ) { - strictEqual( jQuery.type( data ), "array", "JSON results returned (GET, REST-like with param)" ); + ajaxTest( "jQuery.ajax() - JSONP - Query String (?n)" + label, 4, function( assert ) { + return [ + { + url: "data/jsonp.php?callback=?", + dataType: "jsonp", + crossDomain: crossDomain, + success: function( data ) { + assert.ok( data.data, "JSON results returned (GET, url callback)" ); + } + }, + { + url: "data/jsonp.php?callback=??", + dataType: "jsonp", + crossDomain: crossDomain, + success: function( data ) { + assert.ok( data.data, "JSON results returned (GET, url context-free callback)" ); + } + }, + { + url: "data/jsonp.php/??", + dataType: "jsonp", + crossDomain: crossDomain, + success: function( data ) { + assert.ok( data.data, "JSON results returned (GET, REST-like)" ); + } + }, + { + url: "data/jsonp.php/???json=1", + dataType: "jsonp", + crossDomain: crossDomain, + success: function( data ) { + assert.strictEqual( jQuery.type( data ), "array", "JSON results returned (GET, REST-like with param)" ); + } } - } - ]); + ]; + }); - ajaxTest( "jQuery.ajax() - JSONP - Explicit callback param" + label, 10, { - setup: function() { - Globals.register("functionToCleanUp"); - Globals.register("XXX"); - Globals.register("jsonpResults"); - window["jsonpResults"] = function( data ) { - ok( data["data"], "JSON results returned (GET, custom callback function)" ); - }; - }, - requests: [{ - url: "data/jsonp.php", - dataType: "jsonp", - crossDomain: crossDomain, - jsonp: "callback", - success: function( data ) { - ok( data["data"], "JSON results returned (GET, data obj callback)" ); - } - }, { - url: "data/jsonp.php", - dataType: "jsonp", - crossDomain: crossDomain, - jsonpCallback: "jsonpResults", - success: function( data ) { - strictEqual( - typeof window[ "jsonpResults" ], - "function", - "should not rewrite original function" - ); - ok( data.data, "JSON results returned (GET, custom callback name)" ); - } - }, { - url: "data/jsonp.php", - dataType: "jsonp", - crossDomain: crossDomain, - jsonpCallback: "functionToCleanUp", - success: function( data ) { - ok( data["data"], "JSON results returned (GET, custom callback name to be cleaned up)" ); - strictEqual( window["functionToCleanUp"], true, "Callback was removed (GET, custom callback name to be cleaned up)" ); - var xhr; - jQuery.ajax({ - url: "data/jsonp.php", - dataType: "jsonp", - crossDomain: crossDomain, - jsonpCallback: "functionToCleanUp", - beforeSend: function( jqXHR ) { - xhr = jqXHR; - return false; - } - }); - xhr.fail(function() { - ok( true, "Ajax error JSON (GET, custom callback name to be cleaned up)" ); - strictEqual( window["functionToCleanUp"], true, "Callback was removed after early abort (GET, custom callback name to be cleaned up)" ); - }); - } - }, { - url: "data/jsonp.php?callback=XXX", - dataType: "jsonp", - jsonp: false, - jsonpCallback: "XXX", - crossDomain: crossDomain, - beforeSend: function() { - ok( /^data\/jsonp.php\?callback=XXX&_=\d+$/.test( this.url ), "The URL wasn't messed with (GET, custom callback name with no url manipulation)" ); + ajaxTest( "jQuery.ajax() - JSONP - Explicit callback param" + label, 10, function( assert ) { + return { + setup: function() { + Globals.register("functionToCleanUp"); + Globals.register("XXX"); + Globals.register("jsonpResults"); + window["jsonpResults"] = function( data ) { + assert.ok( data["data"], "JSON results returned (GET, custom callback function)" ); + }; }, - success: function( data ) { - ok( data["data"], "JSON results returned (GET, custom callback name with no url manipulation)" ); - } - }] + requests: [{ + url: "data/jsonp.php", + dataType: "jsonp", + crossDomain: crossDomain, + jsonp: "callback", + success: function( data ) { + assert.ok( data["data"], "JSON results returned (GET, data obj callback)" ); + } + }, { + url: "data/jsonp.php", + dataType: "jsonp", + crossDomain: crossDomain, + jsonpCallback: "jsonpResults", + success: function( data ) { + assert.strictEqual( + typeof window[ "jsonpResults" ], + "function", + "should not rewrite original function" + ); + assert.ok( data.data, "JSON results returned (GET, custom callback name)" ); + } + }, { + url: "data/jsonp.php", + dataType: "jsonp", + crossDomain: crossDomain, + jsonpCallback: "functionToCleanUp", + success: function( data ) { + assert.ok( data["data"], "JSON results returned (GET, custom callback name to be cleaned up)" ); + assert.strictEqual( window["functionToCleanUp"], true, "Callback was removed (GET, custom callback name to be cleaned up)" ); + var xhr; + jQuery.ajax({ + url: "data/jsonp.php", + dataType: "jsonp", + crossDomain: crossDomain, + jsonpCallback: "functionToCleanUp", + beforeSend: function( jqXHR ) { + xhr = jqXHR; + return false; + } + }); + xhr.fail(function() { + assert.ok( true, "Ajax error JSON (GET, custom callback name to be cleaned up)" ); + assert.strictEqual( window["functionToCleanUp"], true, "Callback was removed after early abort (GET, custom callback name to be cleaned up)" ); + }); + } + }, { + url: "data/jsonp.php?callback=XXX", + dataType: "jsonp", + jsonp: false, + jsonpCallback: "XXX", + crossDomain: crossDomain, + beforeSend: function() { + assert.ok( /^data\/jsonp.php\?callback=XXX&_=\d+$/.test( this.url ), "The URL wasn't messed with (GET, custom callback name with no url manipulation)" ); + }, + success: function( data ) { + assert.ok( data["data"], "JSON results returned (GET, custom callback name with no url manipulation)" ); + } + }] + }; }); - ajaxTest( "jQuery.ajax() - JSONP - Callback in data" + label, 2, [ - { - url: "data/jsonp.php", - dataType: "jsonp", - crossDomain: crossDomain, - data: "callback=?", - success: function( data ) { - ok( data.data, "JSON results returned (GET, data callback)" ); - } - }, - { - url: "data/jsonp.php", - dataType: "jsonp", - crossDomain: crossDomain, - data: "callback=??", - success: function( data ) { - ok( data.data, "JSON results returned (GET, data context-free callback)" ); + ajaxTest( "jQuery.ajax() - JSONP - Callback in data" + label, 2, function( assert ) { + return [ + { + url: "data/jsonp.php", + dataType: "jsonp", + crossDomain: crossDomain, + data: "callback=?", + success: function( data ) { + assert.ok( data.data, "JSON results returned (GET, data callback)" ); + } + }, + { + url: "data/jsonp.php", + dataType: "jsonp", + crossDomain: crossDomain, + data: "callback=??", + success: function( data ) { + assert.ok( data.data, "JSON results returned (GET, data context-free callback)" ); + } } - } - ]); + ]; + }); - ajaxTest( "jQuery.ajax() - JSONP - POST" + label, 3, [ - { - type: "POST", - url: "data/jsonp.php", - dataType: "jsonp", - crossDomain: crossDomain, - success: function( data ) { - ok( data["data"], "JSON results returned (POST, no callback)" ); + ajaxTest( "jQuery.ajax() - JSONP - POST" + label, 3, function( assert ) { + return [ + { + type: "POST", + url: "data/jsonp.php", + dataType: "jsonp", + crossDomain: crossDomain, + success: function( data ) { + assert.ok( data["data"], "JSON results returned (POST, no callback)" ); + } + }, + { + type: "POST", + url: "data/jsonp.php", + data: "callback=?", + dataType: "jsonp", + crossDomain: crossDomain, + success: function( data ) { + assert.ok( data["data"], "JSON results returned (POST, data callback)" ); + } + }, + { + type: "POST", + url: "data/jsonp.php", + jsonp: "callback", + dataType: "jsonp", + crossDomain: crossDomain, + success: function( data ) { + assert.ok( data["data"], "JSON results returned (POST, data obj callback)" ); + } } - }, - { - type: "POST", - url: "data/jsonp.php", - data: "callback=?", - dataType: "jsonp", - crossDomain: crossDomain, - success: function( data ) { - ok( data["data"], "JSON results returned (POST, data callback)" ); + ]; + }); + + ajaxTest( "jQuery.ajax() - JSONP" + label, 3, function( assert ) { + return [ + { + url: "data/jsonp.php", + dataType: "jsonp", + crossDomain: crossDomain, + success: function( data ) { + assert.ok( data.data, "JSON results returned (GET, no callback)" ); + } + }, + { + create: function( options ) { + var request = jQuery.ajax( options ), + promise = request.then(function( data ) { + assert.ok( data.data, "first request: JSON results returned (GET, no callback)" ); + request = jQuery.ajax( this ).done(function( data ) { + assert.ok( data.data, "this re-used: JSON results returned (GET, no callback)" ); + }); + promise.abort = request.abort; + return request; + }); + promise.abort = request.abort; + return promise; + }, + url: "data/jsonp.php", + dataType: "jsonp", + crossDomain: crossDomain, + success: true } + ]; + }); + + }); + + ajaxTest( "jQuery.ajax() - script, Remote", 2, function( assert ) { + return { + setup: function() { + Globals.register("testBar"); }, - { - type: "POST", - url: "data/jsonp.php", - jsonp: "callback", - dataType: "jsonp", - crossDomain: crossDomain, - success: function( data ) { - ok( data["data"], "JSON results returned (POST, data obj callback)" ); - } + url: window.location.href.replace( /[^\/]*$/, "" ) + "data/testbar.php", + dataType: "script", + success: function() { + assert.strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" ); } - ]); + }; + }); - ajaxTest( "jQuery.ajax() - JSONP" + label, 3, [ - { - url: "data/jsonp.php", - dataType: "jsonp", - crossDomain: crossDomain, - success: function( data ) { - ok( data.data, "JSON results returned (GET, no callback)" ); - } + ajaxTest( "jQuery.ajax() - script, Remote with POST", 3, function( assert ) { + return { + setup: function() { + Globals.register("testBar"); }, - { - create: function( options ) { - var request = jQuery.ajax( options ), - promise = request.then(function( data ) { - ok( data.data, "first request: JSON results returned (GET, no callback)" ); - request = jQuery.ajax( this ).done(function( data ) { - ok( data.data, "this re-used: JSON results returned (GET, no callback)" ); - }); - promise.abort = request.abort; - return request; - }); - promise.abort = request.abort; - return promise; - }, - url: "data/jsonp.php", - dataType: "jsonp", - crossDomain: crossDomain, - success: true + url: window.location.href.replace( /[^\/]*$/, "" ) + "data/testbar.php", + type: "POST", + dataType: "script", + success: function( data, status ) { + assert.strictEqual( window["testBar"], "bar", "Script results returned (POST, no callback)" ); + assert.strictEqual( status, "success", "Script results returned (POST, no callback)" ); } - ]); - + }; }); - ajaxTest( "jQuery.ajax() - script, Remote", 2, { - setup: function() { - Globals.register("testBar"); - }, - url: window.location.href.replace( /[^\/]*$/, "" ) + "data/testbar.php", - dataType: "script", - success: function() { - strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" ); - } + ajaxTest( "jQuery.ajax() - script, Remote with scheme-less URL", 2, function( assert ) { + return { + setup: function() { + Globals.register("testBar"); + }, + url: window.location.href.replace( /[^\/]*$/, "" ).replace( /^.*?\/\//, "//" ) + "data/testbar.php", + dataType: "script", + success: function() { + assert.strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" ); + } + }; }); - ajaxTest( "jQuery.ajax() - script, Remote with POST", 3, { - setup: function() { - Globals.register("testBar"); - }, - url: window.location.href.replace( /[^\/]*$/, "" ) + "data/testbar.php", - type: "POST", - dataType: "script", - success: function( data, status ) { - strictEqual( window["testBar"], "bar", "Script results returned (POST, no callback)" ); - strictEqual( status, "success", "Script results returned (POST, no callback)" ); - } + ajaxTest( "jQuery.ajax() - malformed JSON", 2, function( assert ) { + return { + url: "data/badjson.js", + dataType: "json", + error: function( xhr, msg, detailedMsg ) { + assert.strictEqual( msg, "parsererror", "A parse error occurred." ); + assert.ok( /(invalid|error|exception)/i.test( detailedMsg ), "Detailed parsererror message provided" ); + } + }; }); - ajaxTest( "jQuery.ajax() - script, Remote with scheme-less URL", 2, { - setup: function() { - Globals.register("testBar"); - }, - url: window.location.href.replace( /[^\/]*$/, "" ).replace( /^.*?\/\//, "//" ) + "data/testbar.php", - dataType: "script", - success: function() { - strictEqual( window["testBar"], "bar", "Script results returned (GET, no callback)" ); - } + ajaxTest( "jQuery.ajax() - script by content-type", 2, function() { + return [ + { + url: "data/script.php", + data: { + "header": "script" + }, + success: true + }, + { + url: "data/script.php", + data: { + "header": "ecma" + }, + success: true + } + ]; }); - ajaxTest( "jQuery.ajax() - malformed JSON", 2, { - url: "data/badjson.js", - dataType: "json", - error: function( xhr, msg, detailedMsg ) { - strictEqual( msg, "parsererror", "A parse error occurred." ); - ok( /(invalid|error|exception)/i.test( detailedMsg ), "Detailed parsererror message provided" ); - } + ajaxTest( "jQuery.ajax() - JSON by content-type", 5, function( assert ) { + return { + url: "data/json.php", + data: { + "header": "json", + "json": "array" + }, + success: function( json ) { + assert.ok( json.length >= 2, "Check length" ); + assert.strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" ); + assert.strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" ); + assert.strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" ); + assert.strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" ); + } + }; }); - ajaxTest( "jQuery.ajax() - script by content-type", 2, [ - { - url: "data/script.php", + ajaxTest( "jQuery.ajax() - JSON by content-type disabled with options", 6, function( assert ) { + return { + url: url("data/json.php"), data: { - "header": "script" + "header": "json", + "json": "array" }, - success: true - }, - { - url: "data/script.php", - data: { - "header": "ecma" + contents: { + "json": false }, - success: true - } - ]); - - ajaxTest( "jQuery.ajax() - JSON by content-type", 5, { - url: "data/json.php", - data: { - "header": "json", - "json": "array" - }, - success: function( json ) { - ok( json.length >= 2, "Check length" ); - strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" ); - strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" ); - strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" ); - strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" ); - } - }); - - ajaxTest( "jQuery.ajax() - JSON by content-type disabled with options", 6, { - url: url("data/json.php"), - data: { - "header": "json", - "json": "array" - }, - contents: { - "json": false - }, - success: function( text ) { - strictEqual( typeof text, "string", "json wasn't auto-determined" ); - var json = jQuery.parseJSON( text ); - ok( json.length >= 2, "Check length"); - strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" ); - strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" ); - strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" ); - strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" ); - } + success: function( text ) { + assert.strictEqual( typeof text, "string", "json wasn't auto-determined" ); + var json = jQuery.parseJSON( text ); + assert.ok( json.length >= 2, "Check length"); + assert.strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" ); + assert.strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" ); + assert.strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" ); + assert.strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" ); + } + }; }); - ajaxTest( "jQuery.ajax() - simple get", 1, { - type: "GET", - url: url("data/name.php?name=foo"), - success: function( msg ) { - strictEqual( msg, "bar", "Check for GET" ); - } + ajaxTest( "jQuery.ajax() - simple get", 1, function( assert ) { + return { + type: "GET", + url: url("data/name.php?name=foo"), + success: function( msg ) { + assert.strictEqual( msg, "bar", "Check for GET" ); + } + }; }); - ajaxTest( "jQuery.ajax() - simple post", 1, { - type: "POST", - url: url("data/name.php"), - data: "name=peter", - success: function( msg ) { - strictEqual( msg, "pan", "Check for POST" ); - } + ajaxTest( "jQuery.ajax() - simple post", 1, function( assert ) { + return { + type: "POST", + url: url("data/name.php"), + data: "name=peter", + success: function( msg ) { + assert.strictEqual( msg, "pan", "Check for POST" ); + } + }; }); - ajaxTest( "jQuery.ajax() - data option - empty bodies for non-GET requests", 1, { - url: "data/echoData.php", - data: undefined, - type: "post", - success: function( result ) { - strictEqual( result, "" ); - } + ajaxTest( "jQuery.ajax() - data option - empty bodies for non-GET requests", 1, function( assert ) { + return { + url: "data/echoData.php", + data: undefined, + type: "post", + success: function( result ) { + assert.strictEqual( result, "" ); + } + }; }); var ifModifiedNow = new Date(); @@ -1029,24 +1107,24 @@ module( "ajax", { }, function( type, url ) { url = "data/" + url + "?ts=" + ifModifiedNow++; - asyncTest( "jQuery.ajax() - " + type + " support" + label, 4, function() { + QUnit.asyncTest( "jQuery.ajax() - " + type + " support" + label, 4, function( assert ) { jQuery.ajax({ url: url, ifModified: true, cache: cache, success: function( _, status ) { - strictEqual( status, "success", "Initial status is 'success'" ); + assert.strictEqual( status, "success", "Initial status is 'success'" ); jQuery.ajax({ url: url, ifModified: true, cache: cache, success: function( data, status, jqXHR ) { - strictEqual( status, "notmodified", "Following status is 'notmodified'" ); - strictEqual( jqXHR.status, 304, "XHR status is 304" ); - equal( data, null, "no response body is given" ); + assert.strictEqual( status, "notmodified", "Following status is 'notmodified'" ); + assert.strictEqual( jqXHR.status, 304, "XHR status is 304" ); + assert.equal( data, null, "no response body is given" ); }, complete: function() { - start(); + QUnit.start(); } }); } @@ -1058,46 +1136,52 @@ module( "ajax", { /* jQuery.each arguments end */ ); - ajaxTest( "jQuery.ajax() - failing cross-domain (non-existing)", 1, { - // see RFC 2606 - url: "http://example.invalid", - error: function( xhr, _, e ) { - ok( true, "file not found: " + xhr.status + " => " + e ); - } + ajaxTest( "jQuery.ajax() - failing cross-domain (non-existing)", 1, function( assert ) { + return { + // see RFC 2606 + url: "http://example.invalid", + error: function( xhr, _, e ) { + assert.ok( true, "file not found: " + xhr.status + " => " + e ); + } + }; }); - ajaxTest( "jQuery.ajax() - failing cross-domain", 1, { - url: "http://" + externalHost, - error: function( xhr, _, e ) { - ok( true, "access denied: " + xhr.status + " => " + e ); - } + ajaxTest( "jQuery.ajax() - failing cross-domain", 1, function( assert ) { + return { + url: "http://" + externalHost, + error: function( xhr, _, e ) { + assert.ok( true, "access denied: " + xhr.status + " => " + e ); + } + }; }); - ajaxTest( "jQuery.ajax() - atom+xml", 1, { - url: url("data/atom+xml.php"), - success: function() { - ok( true, "success" ); - } + ajaxTest( "jQuery.ajax() - atom+xml", 1, function( assert ) { + return { + url: url("data/atom+xml.php"), + success: function() { + assert.ok( true, "success" ); + } + }; }); - asyncTest( "jQuery.ajax() - statusText", 3, function() { + QUnit.asyncTest( "jQuery.ajax() - statusText", 3, function( assert ) { jQuery.ajax( url("data/statusText.php?status=200&text=Hello") ).done(function( _, statusText, jqXHR ) { - strictEqual( statusText, "success", "callback status text ok for success" ); - ok( jqXHR.statusText === "Hello" || jqXHR.statusText === "OK", "jqXHR status text ok for success (" + jqXHR.statusText + ")" ); + assert.strictEqual( statusText, "success", "callback status text ok for success" ); + assert.ok( jqXHR.statusText === "Hello" || jqXHR.statusText === "OK", "jqXHR status text ok for success (" + jqXHR.statusText + ")" ); jQuery.ajax( url("data/statusText.php?status=404&text=World") ).fail(function( jqXHR, statusText ) { - strictEqual( statusText, "error", "callback status text ok for error" ); - start(); + assert.strictEqual( statusText, "error", "callback status text ok for error" ); + QUnit.start(); }); }); }); - asyncTest( "jQuery.ajax() - statusCode", 20, function() { + QUnit.asyncTest( "jQuery.ajax() - statusCode", 20, function( assert ) { var count = 12; function countComplete() { if ( ! --count ) { - start(); + QUnit.start(); } } @@ -1105,10 +1189,10 @@ module( "ajax", { name = "Test " + name + " " + ( isSuccess ? "success" : "error" ); return { 200: function() { - ok( isSuccess, name ); + assert.ok( isSuccess, name ); }, 404: function() { - ok( !isSuccess, name ); + assert.ok( !isSuccess, name ); } }; } @@ -1161,7 +1245,7 @@ module( "ajax", { jQuery.ajax( url(uri), { success: function( a, b, jqXHR ) { - ok( isSuccess, "success" ); + assert.ok( isSuccess, "success" ); var statusCode = {}; statusCode[ jqXHR.status ] = function() { testString += "B"; @@ -1170,7 +1254,7 @@ module( "ajax", { testString += "A"; }, error: function( jqXHR ) { - ok( !isSuccess, "error" ); + assert.ok( !isSuccess, "error" ); var statusCode = {}; statusCode[ jqXHR.status ] = function() { testString += "B"; @@ -1179,7 +1263,7 @@ module( "ajax", { testString += "A"; }, complete: function() { - strictEqual( + assert.strictEqual( testString, "AB", "Test statusCode callbacks are ordered like " + ( isSuccess ? "success" : "error" ) + " callbacks" @@ -1193,105 +1277,115 @@ module( "ajax", { ); }); - ajaxTest( "jQuery.ajax() - transitive conversions", 8, [ - { - url: url("data/json.php"), - converters: { - "json myJson": function( data ) { - ok( true, "converter called" ); - return data; + ajaxTest( "jQuery.ajax() - transitive conversions", 8, function( assert ) { + return [ + { + url: url("data/json.php"), + converters: { + "json myJson": function( data ) { + assert.ok( true, "converter called" ); + return data; + } + }, + dataType: "myJson", + success: function() { + assert.ok( true, "Transitive conversion worked" ); + assert.strictEqual( this.dataTypes[ 0 ], "text", "response was retrieved as text" ); + assert.strictEqual( this.dataTypes[ 1 ], "myjson", "request expected myjson dataType" ); } }, - dataType: "myJson", - success: function() { - ok( true, "Transitive conversion worked" ); - strictEqual( this.dataTypes[ 0 ], "text", "response was retrieved as text" ); - strictEqual( this.dataTypes[ 1 ], "myjson", "request expected myjson dataType" ); - } - }, - { - url: url("data/json.php"), - converters: { - "json myJson": function( data ) { - ok( true, "converter called (*)" ); - return data; + { + url: url("data/json.php"), + converters: { + "json myJson": function( data ) { + assert.ok( true, "converter called (*)" ); + return data; + } + }, + contents: false, /* headers are wrong so we ignore them */ + dataType: "* myJson", + success: function() { + assert.ok( true, "Transitive conversion worked (*)" ); + assert.strictEqual( this.dataTypes[ 0 ], "text", "response was retrieved as text (*)" ); + assert.strictEqual( this.dataTypes[ 1 ], "myjson", "request expected myjson dataType (*)" ); } - }, - contents: false, /* headers are wrong so we ignore them */ - dataType: "* myJson", - success: function() { - ok( true, "Transitive conversion worked (*)" ); - strictEqual( this.dataTypes[ 0 ], "text", "response was retrieved as text (*)" ); - strictEqual( this.dataTypes[ 1 ], "myjson", "request expected myjson dataType (*)" ); } - } - ]); + ]; + }); - ajaxTest( "jQuery.ajax() - overrideMimeType", 2, [ - { - url: url("data/json.php"), - beforeSend: function( xhr ) { - xhr.overrideMimeType( "application/json" ); + ajaxTest( "jQuery.ajax() - overrideMimeType", 2, function( assert ) { + return [ + { + url: url("data/json.php"), + beforeSend: function( xhr ) { + xhr.overrideMimeType( "application/json" ); + }, + success: function( json ) { + assert.ok( json.data, "Mimetype overridden using beforeSend" ); + } }, - success: function( json ) { - ok( json.data, "Mimetype overridden using beforeSend" ); - } - }, - { - url: url("data/json.php"), - mimeType: "application/json", - success: function( json ) { - ok( json.data, "Mimetype overridden using mimeType option" ); + { + url: url("data/json.php"), + mimeType: "application/json", + success: function( json ) { + assert.ok( json.data, "Mimetype overridden using mimeType option" ); + } } - } - ]); + ]; + }); - ajaxTest( "jQuery.ajax() - empty json gets to error callback instead of success callback.", 1, { - url: url("data/echoData.php"), - error: function( _, __, error ) { - equal( typeof error === "object", true, "Didn't get back error object for empty json response" ); - }, - dataType: "json" + ajaxTest( "jQuery.ajax() - empty json gets to error callback instead of success callback.", 1, function( assert ) { + return { + url: url("data/echoData.php"), + error: function( _, __, error ) { + assert.equal( typeof error === "object", true, "Didn't get back error object for empty json response" ); + }, + dataType: "json" + }; }); - ajaxTest( "#2688 - jQuery.ajax() - beforeSend, cancel request", 2, { - create: function() { - return jQuery.ajax({ - url: url("data/name.html"), - beforeSend: function() { - ok( true, "beforeSend got called, canceling" ); - return false; - }, - success: function() { - ok( false, "request didn't get canceled" ); - }, - complete: function() { - ok( false, "request didn't get canceled" ); - }, - error: function() { - ok( false, "request didn't get canceled" ); - } - }); - }, - fail: function( _, reason ) { - strictEqual( reason, "canceled", "canceled request must fail with 'canceled' status text" ); - } + ajaxTest( "#2688 - jQuery.ajax() - beforeSend, cancel request", 2, function( assert ) { + return { + create: function() { + return jQuery.ajax({ + url: url("data/name.html"), + beforeSend: function() { + assert.ok( true, "beforeSend got called, canceling" ); + return false; + }, + success: function() { + assert.ok( false, "request didn't get canceled" ); + }, + complete: function() { + assert.ok( false, "request didn't get canceled" ); + }, + error: function() { + assert.ok( false, "request didn't get canceled" ); + } + }); + }, + fail: function( _, reason ) { + assert.strictEqual( reason, "canceled", "canceled request must fail with 'canceled' status text" ); + } + }; }); - ajaxTest( "#2806 - jQuery.ajax() - data option - evaluate function values", 1, { - url: "data/echoQuery.php", - data: { - key: function() { - return "value"; + ajaxTest( "#2806 - jQuery.ajax() - data option - evaluate function values", 1, function( assert ) { + return { + url: "data/echoQuery.php", + data: { + key: function() { + return "value"; + } + }, + success: function( result ) { + assert.strictEqual( result, "key=value" ); } - }, - success: function( result ) { - strictEqual( result, "key=value" ); - } + }; }); - test( "#7531 - jQuery.ajax() - Location object as url", function () { - expect( 1 ); + QUnit.test( "#7531 - jQuery.ajax() - Location object as url", function( assert ) { + assert.expect( 1 ); var xhr, success = false; @@ -1304,97 +1398,103 @@ module( "ajax", { } catch (e) { } - ok( success, "document.location did not generate exception" ); + assert.ok( success, "document.location did not generate exception" ); }); jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) { - ajaxTest( "#7578 - jQuery.ajax() - JSONP - default for cache option" + label, 1, { - url: "data/jsonp.php", - dataType: "jsonp", - crossDomain: crossDomain, - beforeSend: function() { - strictEqual( this.cache, false, "cache must be false on JSON request" ); - return false; - }, - error: true + ajaxTest( "#7578 - jQuery.ajax() - JSONP - default for cache option" + label, 1, function( assert ) { + return { + url: "data/jsonp.php", + dataType: "jsonp", + crossDomain: crossDomain, + beforeSend: function() { + assert.strictEqual( this.cache, false, "cache must be false on JSON request" ); + return false; + }, + error: true + }; }); }); - ajaxTest( "#8107 - jQuery.ajax() - multiple method signatures introduced in 1.5", 4, [ - { - create: function() { - return jQuery.ajax(); - }, - done: function() { - ok( true, "With no arguments" ); - } - }, - { - create: function() { - return jQuery.ajax("data/name.html"); + ajaxTest( "#8107 - jQuery.ajax() - multiple method signatures introduced in 1.5", 4, function( assert ) { + return [ + { + create: function() { + return jQuery.ajax(); + }, + done: function() { + assert.ok( true, "With no arguments" ); + } }, - done: function() { - ok( true, "With only string URL argument" ); - } - }, - { - create: function() { - return jQuery.ajax( "data/name.html", {}); + { + create: function() { + return jQuery.ajax("data/name.html"); + }, + done: function() { + assert.ok( true, "With only string URL argument" ); + } }, - done: function() { - ok( true, "With string URL param and map" ); - } - }, - { - create: function( options ) { - return jQuery.ajax( options ); + { + create: function() { + return jQuery.ajax( "data/name.html", {}); + }, + done: function() { + assert.ok( true, "With string URL param and map" ); + } }, - url: "data/name.html", - success: function() { - ok( true, "With only map" ); + { + create: function( options ) { + return jQuery.ajax( options ); + }, + url: "data/name.html", + success: function() { + assert.ok( true, "With only map" ); + } } - } - ]); + ]; + }); jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) { - ajaxTest( "#8205 - jQuery.ajax() - JSONP - re-use callbacks name" + label, 4, { - url: "data/jsonp.php", - dataType: "jsonp", - crossDomain: crossDomain, - beforeSend: function( jqXHR, s ) { - s.callback = s.jsonpCallback; + ajaxTest( "#8205 - jQuery.ajax() - JSONP - re-use callbacks name" + label, 4, function( assert ) { + return { + url: "data/jsonp.php", + dataType: "jsonp", + crossDomain: crossDomain, + beforeSend: function( jqXHR, s ) { + s.callback = s.jsonpCallback; - ok( this.callback in window, "JSONP callback name is in the window" ); - }, - success: function() { - var previous = this; + assert.ok( this.callback in window, "JSONP callback name is in the window" ); + }, + success: function() { + var previous = this; - strictEqual( - previous.jsonpCallback, - undefined, - "jsonpCallback option is set back to default in callbacks" - ); + assert.strictEqual( + previous.jsonpCallback, + undefined, + "jsonpCallback option is set back to default in callbacks" + ); - ok( - !( this.callback in window ), - "JSONP callback name was removed from the window" - ); + assert.ok( + !( this.callback in window ), + "JSONP callback name was removed from the window" + ); - jQuery.ajax({ - url: "data/jsonp.php", - dataType: "jsonp", - crossDomain: crossDomain, - beforeSend: function() { - strictEqual( this.jsonpCallback, previous.callback, "JSONP callback name is re-used" ); - return false; - } - }); - } + jQuery.ajax({ + url: "data/jsonp.php", + dataType: "jsonp", + crossDomain: crossDomain, + beforeSend: function() { + assert.strictEqual( this.jsonpCallback, previous.callback, "JSONP callback name is re-used" ); + return false; + } + }); + } + }; }); }); - test( "#9887 - jQuery.ajax() - Context with circular references (#9887)", function () { - expect( 2 ); + QUnit.test( "#9887 - jQuery.ajax() - Context with circular references (#9887)", function( assert ) { + assert.expect( 2 ); var success = false, context = {}; @@ -1403,7 +1503,7 @@ module( "ajax", { jQuery.ajax( "non-existing", { context: context, beforeSend: function() { - ok( this === context, "context was not deep extended" ); + assert.ok( this === context, "context was not deep extended" ); return false; } }); @@ -1411,65 +1511,70 @@ module( "ajax", { } catch ( e ) { console.log( e ); } - ok( success, "context with circular reference did not generate an exception" ); + assert.ok( success, "context with circular reference did not generate an exception" ); }); jQuery.each( [ "as argument", "in settings object" ], function( inSetting, title ) { - function request( url, test ) { + function request( assert, url, test ) { return { create: function() { return jQuery.ajax( inSetting ? { url: url } : url ); }, done: function() { - ok( true, ( test || url ) + " " + title ); + assert.ok( true, ( test || url ) + " " + title ); } }; } - ajaxTest( "#10093 - jQuery.ajax() - falsy url " + title, 4, [ - request( "", "empty string" ), - request( false ), - request( null ), - request( undefined ) - ]); - + ajaxTest( "#10093 - jQuery.ajax() - falsy url " + title, 4, function( assert ) { + return [ + request( assert, "", "empty string" ), + request( assert, false ), + request( assert, null ), + request( assert, undefined ) + ]; + }); }); - ajaxTest( "#11151 - jQuery.ajax() - parse error body", 2, { - url: url("data/errorWithJSON.php"), - dataFilter: function( string ) { - ok( false, "dataFilter called" ); - return string; - }, - error: function( jqXHR ) { - strictEqual( jqXHR.responseText, "{ \"code\": 40, \"message\": \"Bad Request\" }", "Error body properly set" ); - deepEqual( jqXHR.responseJSON, { code: 40, message: "Bad Request" }, "Error body properly parsed" ); - } + ajaxTest( "#11151 - jQuery.ajax() - parse error body", 2, function( assert ) { + return { + url: url("data/errorWithJSON.php"), + dataFilter: function( string ) { + assert.ok( false, "dataFilter called" ); + return string; + }, + error: function( jqXHR ) { + assert.strictEqual( jqXHR.responseText, "{ \"code\": 40, \"message\": \"Bad Request\" }", "Error body properly set" ); + assert.deepEqual( jqXHR.responseJSON, { code: 40, message: "Bad Request" }, "Error body properly parsed" ); + } + }; }); - ajaxTest( "#11426 - jQuery.ajax() - loading binary data shouldn't throw an exception in IE", 1, { - url: url("data/1x1.jpg"), - success: function( data ) { - ok( data === undefined || /JFIF/.test( data ), "success callback reached" ); - } + ajaxTest( "#11426 - jQuery.ajax() - loading binary data shouldn't throw an exception in IE", 1, function( assert ) { + return { + url: url("data/1x1.jpg"), + success: function( data ) { + assert.ok( data === undefined || /JFIF/.test( data ), "success callback reached" ); + } + }; }); - asyncTest( "#11743 - jQuery.ajax() - script, throws exception", 1, function() { + QUnit.asyncTest( "#11743 - jQuery.ajax() - script, throws exception", 1, function( assert ) { // Support: Android 2.3 only // Android 2.3 doesn't fire the window.onerror handler, just accept the reality there. if ( /android 2\.3/i.test( navigator.userAgent ) ) { - ok( true, "Test skipped, Android 2.3 doesn't fire window.onerror for " + + assert.ok( true, "Test skipped, Android 2.3 doesn't fire window.onerror for " + "errors in dynamically included scripts" ); - start(); + QUnit.start(); return; } var onerror = window.onerror; window.onerror = function() { - ok( true, "Exception thrown" ); + assert.ok( true, "Exception thrown" ); window.onerror = onerror; - start(); + QUnit.start(); }; jQuery.ajax({ url: "data/badjson.js", @@ -1479,121 +1584,137 @@ module( "ajax", { }); jQuery.each( [ "method", "type" ], function( _, globalOption ) { - - function request( option ) { + function request( assert, option ) { var options = { url: url("data/echoData.php"), data: "hello", success: function( msg ) { - strictEqual( msg, "hello", "Check for POST (no override)" ); + assert.strictEqual( msg, "hello", "Check for POST (no override)" ); } }; if ( option ) { options[ option ] = "GET"; options.success = function( msg ) { - strictEqual( msg, "", "Check for no POST (overriding with " + option + ")" ); + assert.strictEqual( msg, "", "Check for no POST (overriding with " + option + ")" ); }; } return options; } - ajaxTest( "#12004 - jQuery.ajax() - method is an alias of type - " + globalOption + " set globally", 3, { - setup: function() { - var options = {}; - options[ globalOption ] = "POST"; - jQuery.ajaxSetup( options ); - }, - requests: [ - request("type"), - request("method"), - request() - ] - }); - + ajaxTest( + "#12004 - jQuery.ajax() - method is an alias of type - " + + globalOption + " set globally", 3, + function( assert ) { + return { + setup: function() { + var options = {}; + options[ globalOption ] = "POST"; + jQuery.ajaxSetup( options ); + }, + requests: [ + request(assert, "type"), + request(assert, "method"), + request(assert ) + ] + }; + } + ); }); - ajaxTest( "#13276 - jQuery.ajax() - compatibility between XML documents from ajax requests and parsed string", 1, { - url: "data/dashboard.xml", - dataType: "xml", - success: function( ajaxXML ) { - var parsedXML = jQuery( jQuery.parseXML("blibli") ).find("tab"); - ajaxXML = jQuery( ajaxXML ); - try { - // Android 2.3 doesn't automatically adopt nodes from foreign documents. - // (see the comment in test/manipulation.js) - // Support: Android 2.3 - if ( /android 2\.3/i.test( navigator.userAgent ) ) { - parsedXML = jQuery( ajaxXML[ 0 ].adoptNode( parsedXML[ 0 ] ) ); + ajaxTest( "#13276 - jQuery.ajax() - compatibility between XML documents from ajax requests and parsed string", 1, function( assert ) { + return { + url: "data/dashboard.xml", + dataType: "xml", + success: function( ajaxXML ) { + var parsedXML = jQuery( jQuery.parseXML("blibli") ).find("tab"); + ajaxXML = jQuery( ajaxXML ); + try { + // Android 2.3 doesn't automatically adopt nodes from foreign documents. + // (see the comment in test/manipulation.js) + // Support: Android 2.3 + if ( /android 2\.3/i.test( navigator.userAgent ) ) { + parsedXML = jQuery( ajaxXML[ 0 ].adoptNode( parsedXML[ 0 ] ) ); + } + ajaxXML.find("infowindowtab").append( parsedXML ); + } catch( e ) { + assert.strictEqual( e, undefined, "error" ); + return; } - ajaxXML.find("infowindowtab").append( parsedXML ); - } catch( e ) { - strictEqual( e, undefined, "error" ); - return; + assert.strictEqual( ajaxXML.find("tab").length, 3, "Parsed node was added properly" ); } - strictEqual( ajaxXML.find("tab").length, 3, "Parsed node was added properly" ); - } + }; }); - ajaxTest( "#13292 - jQuery.ajax() - converter is bypassed for 204 requests", 3, { - url: "data/nocontent.php", - dataType: "testing", - converters: { - "* testing": function() { - throw "converter was called"; + ajaxTest( "#13292 - jQuery.ajax() - converter is bypassed for 204 requests", 3, function( assert ) { + return { + url: "data/nocontent.php", + dataType: "testing", + converters: { + "* testing": function() { + throw "converter was called"; + } + }, + success: function( data, status, jqXHR ) { + assert.strictEqual( jqXHR.status, 204, "status code is 204" ); + assert.strictEqual( status, "nocontent", "status text is 'nocontent'" ); + assert.strictEqual( data, undefined, "data is undefined" ); + }, + error: function( _, status, error ) { + assert.ok( false, "error" ); + assert.strictEqual( status, "parsererror", "Parser Error" ); + assert.strictEqual( error, "converter was called", "Converter was called" ); } - }, - success: function( data, status, jqXHR ) { - strictEqual( jqXHR.status, 204, "status code is 204" ); - strictEqual( status, "nocontent", "status text is 'nocontent'" ); - strictEqual( data, undefined, "data is undefined" ); - }, - error: function( _, status, error ) { - ok( false, "error" ); - strictEqual( status, "parsererror", "Parser Error" ); - strictEqual( error, "converter was called", "Converter was called" ); - } + }; }); - ajaxTest( "#13388 - jQuery.ajax() - responseXML", 3, { - url: url("data/with_fries.xml"), - dataType: "xml", - success: function( resp, _, jqXHR ) { - notStrictEqual( resp, undefined, "XML document exists" ); - ok( "responseXML" in jqXHR, "jqXHR.responseXML exists" ); - strictEqual( resp, jqXHR.responseXML, "jqXHR.responseXML is set correctly" ); - } + ajaxTest( "#13388 - jQuery.ajax() - responseXML", 3, function( assert ) { + return { + url: url("data/with_fries.xml"), + dataType: "xml", + success: function( resp, _, jqXHR ) { + assert.notStrictEqual( resp, undefined, "XML document exists" ); + assert.ok( "responseXML" in jqXHR, "jqXHR.responseXML exists" ); + assert.strictEqual( resp, jqXHR.responseXML, "jqXHR.responseXML is set correctly" ); + } + }; }); - ajaxTest( "#13922 - jQuery.ajax() - converter is bypassed for HEAD requests", 3, { - url: "data/json.php", - method: "HEAD", - data: { - header: "yes" - }, - converters: { - "text json": function() { - throw "converter was called"; + ajaxTest( "#13922 - jQuery.ajax() - converter is bypassed for HEAD requests", 3, function( assert ) { + return { + url: "data/json.php", + method: "HEAD", + data: { + header: "yes" + }, + converters: { + "text json": function() { + throw "converter was called"; + } + }, + success: function( data, status ) { + assert.ok( true, "success" ); + assert.strictEqual( status, "nocontent", "data is undefined" ); + assert.strictEqual( data, undefined, "data is undefined" ); + }, + error: function( _, status, error ) { + assert.ok( false, "error" ); + assert.strictEqual( status, "parsererror", "Parser Error" ); + assert.strictEqual( error, "converter was called", "Converter was called" ); } - }, - success: function( data, status ) { - ok( true, "success" ); - strictEqual( status, "nocontent", "data is undefined" ); - strictEqual( data, undefined, "data is undefined" ); - }, - error: function( _, status, error ) { - ok( false, "error" ); - strictEqual( status, "parsererror", "Parser Error" ); - strictEqual( error, "converter was called", "Converter was called" ); - } - } ); - - testIframeWithCallback( "#14379 - jQuery.ajax() on unload", "ajax/onunload.html", function( status ) { - expect( 1 ); - strictEqual( status, "success", "Request completed" ); + }; }); - ajaxTest( "#14683 - jQuery.ajax() - Exceptions thrown synchronously by xhr.send should be caught", 4, [ - { + testIframeWithCallback( + "#14379 - jQuery.ajax() on unload", + "ajax/onunload.html", + function( status, assert ) { + assert.expect( 1 ); + assert.strictEqual( status, "success", "Request completed" ); + } + ); + + ajaxTest( "#14683 - jQuery.ajax() - Exceptions thrown synchronously by xhr.send should be caught", 4, function( assert ) { + return [{ url: "data/params_html.php", method: "POST", data: { @@ -1603,71 +1724,73 @@ module( "ajax", { }, processData: false, done: function( data ) { - ok( false, "done: " + data ); - }, - fail: function( jqXHR, status, error ) { - ok( true, "exception caught: " + error ); - strictEqual( jqXHR.status, 0, "proper status code" ); - strictEqual( status, "error", "proper status" ); - } - }, - { - url: "http://domain.org:80d", - done: function( data ) { - ok( false, "done: " + data ); + assert.ok( false, "done: " + data ); }, - fail: function( _, status, error ) { - ok( true, "fail: " + status + " - " + error ); - } + fail: function( jqXHR, status, error ) { + assert.ok( true, "exception caught: " + error ); + assert.strictEqual( jqXHR.status, 0, "proper status code" ); + assert.strictEqual( status, "error", "proper status" ); + } + }, { + url: "http://domain.org:80d", + done: function( data ) { + assert.ok( false, "done: " + data ); + }, + fail: function( _, status, error ) { + assert.ok( true, "fail: " + status + " - " + error ); + } + }]; } - ]); + ); -//----------- jQuery.ajaxPrefilter() +// //----------- jQuery.ajaxPrefilter() - ajaxTest( "jQuery.ajaxPrefilter() - abort", 1, { - dataType: "prefix", - setup: function() { - // Ensure prefix does not throw an error - jQuery.ajaxPrefilter("+prefix", function( options, _, jqXHR ) { - if ( options.abortInPrefilter ) { - jqXHR.abort(); - } - }); - }, - abortInPrefilter: true, - error: function() { - ok( false, "error callback called" ); - }, - fail: function( _, reason ) { - strictEqual( reason, "canceled", "Request aborted by the prefilter must fail with 'canceled' status text" ); - } + ajaxTest( "jQuery.ajaxPrefilter() - abort", 1, function( assert ) { + return { + dataType: "prefix", + setup: function() { + // Ensure prefix does not throw an error + jQuery.ajaxPrefilter("+prefix", function( options, _, jqXHR ) { + if ( options.abortInPrefilter ) { + jqXHR.abort(); + } + }); + }, + abortInPrefilter: true, + error: function() { + assert.ok( false, "error callback called" ); + }, + fail: function( _, reason ) { + assert.strictEqual( reason, "canceled", "Request aborted by the prefilter must fail with 'canceled' status text" ); + } + }; }); //----------- jQuery.ajaxSetup() - asyncTest( "jQuery.ajaxSetup()", 1, function() { + QUnit.asyncTest( "jQuery.ajaxSetup()", 1, function( assert ) { jQuery.ajaxSetup({ url: url("data/name.php?name=foo"), success: function( msg ) { - strictEqual( msg, "bar", "Check for GET" ); - start(); + assert.strictEqual( msg, "bar", "Check for GET" ); + QUnit.start(); } }); jQuery.ajax(); }); - asyncTest( "jQuery.ajaxSetup({ timeout: Number }) - with global timeout", 2, function() { + QUnit.asyncTest( "jQuery.ajaxSetup({ timeout: Number }) - with global timeout", 2, function( assert ) { var passed = 0, pass = function() { - ok( passed++ < 2, "Error callback executed" ); + assert.ok( passed++ < 2, "Error callback executed" ); if ( passed === 2 ) { jQuery( document ).off("ajaxError.setupTest"); - start(); + QUnit.start(); } }, fail = function( a, b ) { - ok( false, "Check for timeout failed " + a + " " + b ); - start(); + assert.ok( false, "Check for timeout failed " + a + " " + b ); + QUnit.start(); }; jQuery( document ).on( "ajaxError.setupTest", pass ); @@ -1684,7 +1807,7 @@ module( "ajax", { }); }); - asyncTest( "jQuery.ajaxSetup({ timeout: Number }) with localtimeout", 1, function() { + QUnit.asyncTest( "jQuery.ajaxSetup({ timeout: Number }) with localtimeout", 1, function( assert ) { jQuery.ajaxSetup({ timeout: 50 }); @@ -1693,27 +1816,27 @@ module( "ajax", { timeout: 15000, url: url("data/name.php?wait=1"), error: function() { - ok( false, "Check for local timeout failed" ); - start(); + assert.ok( false, "Check for local timeout failed" ); + QUnit.start(); }, success: function() { - ok( true, "Check for local timeout" ); - start(); + assert.ok( true, "Check for local timeout" ); + QUnit.start(); } }); }); //----------- jQuery.domManip() - test( "#11264 - jQuery.domManip() - no side effect because of ajaxSetup or global events", function() { - expect( 1 ); + QUnit.test( "#11264 - jQuery.domManip() - no side effect because of ajaxSetup or global events", function( assert ) { + assert.expect( 1 ); jQuery.ajaxSetup({ type: "POST" }); jQuery( document ).on( "ajaxStart ajaxStop", function() { - ok( false, "Global event triggered" ); + assert.ok( false, "Global event triggered" ); }); jQuery("#qunit-fixture").append(""); @@ -1721,232 +1844,238 @@ module( "ajax", { jQuery( document ).off("ajaxStart ajaxStop"); }); - asyncTest( "jQuery#load() - always use GET method even if it overrided through ajaxSetup (#11264)", 1, function() { + QUnit.asyncTest( "jQuery#load() - always use GET method even if it overrided through ajaxSetup (#11264)", 1, function( assert ) { jQuery.ajaxSetup({ type: "POST" }); jQuery( "#qunit-fixture" ).load( "data/ajax/method.php", function( method ) { - equal( method, "GET" ); - start(); + assert.equal( method, "GET" ); + QUnit.start(); }); }); - asyncTest( "#11402 - jQuery.domManip() - script in comments are properly evaluated", 2, function() { + QUnit.asyncTest( "#11402 - jQuery.domManip() - script in comments are properly evaluated", 2, function() { jQuery("#qunit-fixture").load( "data/cleanScript.html", start ); }); //----------- jQuery.get() - asyncTest( "jQuery.get( String, Hash, Function ) - parse xml and use text() on nodes", 2, function() { + QUnit.asyncTest( "jQuery.get( String, Hash, Function ) - parse xml and use text() on nodes", 2, function( assert ) { jQuery.get( url("data/dashboard.xml"), function( xml ) { var content = []; jQuery( "tab", xml ).each(function() { content.push( jQuery( this ).text() ); }); - strictEqual( content[ 0 ], "blabla", "Check first tab" ); - strictEqual( content[ 1 ], "blublu", "Check second tab" ); - start(); + assert.strictEqual( content[ 0 ], "blabla", "Check first tab" ); + assert.strictEqual( content[ 1 ], "blublu", "Check second tab" ); + QUnit.start(); }); }); - asyncTest( "#8277 - jQuery.get( String, Function ) - data in ajaxSettings", 1, function() { + QUnit.asyncTest( "#8277 - jQuery.get( String, Function ) - data in ajaxSettings", 1, function( assert ) { jQuery.ajaxSetup({ data: "helloworld" }); jQuery.get( url("data/echoQuery.php"), function( data ) { - ok( /helloworld$/.test( data ), "Data from ajaxSettings was used" ); - start(); + assert.ok( /helloworld$/.test( data ), "Data from ajaxSettings was used" ); + QUnit.start(); }); }); //----------- jQuery.getJSON() - asyncTest( "jQuery.getJSON( String, Hash, Function ) - JSON array", 5, function() { + QUnit.asyncTest( "jQuery.getJSON( String, Hash, Function ) - JSON array", 5, function( assert ) { jQuery.getJSON( url("data/json.php"), { "json": "array" }, function( json ) { - ok( json.length >= 2, "Check length" ); - strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" ); - strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" ); - strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" ); - strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" ); - start(); + assert.ok( json.length >= 2, "Check length" ); + assert.strictEqual( json[ 0 ]["name"], "John", "Check JSON: first, name" ); + assert.strictEqual( json[ 0 ]["age"], 21, "Check JSON: first, age" ); + assert.strictEqual( json[ 1 ]["name"], "Peter", "Check JSON: second, name" ); + assert.strictEqual( json[ 1 ]["age"], 25, "Check JSON: second, age" ); + QUnit.start(); } ); }); - asyncTest( "jQuery.getJSON( String, Function ) - JSON object", 2, function() { + QUnit.asyncTest( "jQuery.getJSON( String, Function ) - JSON object", 2, function( assert ) { jQuery.getJSON( url("data/json.php"), function( json ) { if ( json && json["data"] ) { - strictEqual( json["data"]["lang"], "en", "Check JSON: lang" ); - strictEqual( json["data"].length, 25, "Check JSON: length" ); - start(); + assert.strictEqual( json["data"]["lang"], "en", "Check JSON: lang" ); + assert.strictEqual( json["data"].length, 25, "Check JSON: length" ); + QUnit.start(); } }); }); - asyncTest( "jQuery.getJSON( String, Function ) - JSON object with absolute url to local content", 2, function() { + QUnit.asyncTest( "jQuery.getJSON( String, Function ) - JSON object with absolute url to local content", 2, function( assert ) { jQuery.getJSON( url( window.location.href.replace( /[^\/]*$/, "" ) + "data/json.php" ), function( json ) { - strictEqual( json.data.lang, "en", "Check JSON: lang" ); - strictEqual( json.data.length, 25, "Check JSON: length" ); - start(); + assert.strictEqual( json.data.lang, "en", "Check JSON: lang" ); + assert.strictEqual( json.data.length, 25, "Check JSON: length" ); + QUnit.start(); }); }); //----------- jQuery.getScript() - asyncTest( "jQuery.getScript( String, Function ) - with callback", 2, function() { + QUnit.asyncTest( "jQuery.getScript( String, Function ) - with callback", 2, function( assert ) { Globals.register("testBar"); jQuery.getScript( url("data/testbar.php"), function() { - strictEqual( window["testBar"], "bar", "Check if script was evaluated" ); - start(); + assert.strictEqual( window["testBar"], "bar", "Check if script was evaluated" ); + QUnit.start(); }); }); - asyncTest( "jQuery.getScript( String, Function ) - no callback", 1, function() { + QUnit.asyncTest( "jQuery.getScript( String, Function ) - no callback", 1, function() { Globals.register("testBar"); jQuery.getScript( url("data/testbar.php") ).done( start ); }); - asyncTest( "#8082 - jQuery.getScript( String, Function ) - source as responseText", 2, function() { + QUnit.asyncTest( "#8082 - jQuery.getScript( String, Function ) - source as responseText", 2, function( assert ) { Globals.register("testBar"); jQuery.getScript( url("data/testbar.php"), function( data, _, jqXHR ) { - strictEqual( data, jqXHR.responseText, "Same-domain script requests returns the source of the script" ); - start(); + assert.strictEqual( data, jqXHR.responseText, "Same-domain script requests returns the source of the script" ); + QUnit.start(); }); }); -//----------- jQuery.fn.load() +// //----------- jQuery.fn.load() // check if load can be called with only url - asyncTest( "jQuery.fn.load( String )", 2, function() { + QUnit.asyncTest( "jQuery.fn.load( String )", 2, function( assert ) { jQuery.ajaxSetup({ beforeSend: function() { - strictEqual( this.type, "GET", "no data means GET request" ); + assert.strictEqual( this.type, "GET", "no data means GET request" ); } }); jQuery("#first").load( "data/name.html", start ); }); - asyncTest( "jQuery.fn.load() - 404 error callbacks", 6, function() { - addGlobalEvents("ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError")(); - jQuery( document ).ajaxStop( start ); + QUnit.test( "jQuery.fn.load() - 404 error callbacks", function( assert ) { + assert.expect( 6 ); + var done = assert.async(); + + addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError", assert )(); + jQuery( document ).ajaxStop( done ); jQuery("
").load( "data/404.html", function() { - ok( true, "complete" ); + assert.ok( true, "complete" ); }); }); // check if load can be called with url and null data - asyncTest( "jQuery.fn.load( String, null )", 2, function() { + QUnit.asyncTest( "jQuery.fn.load( String, null )", 2, function( assert ) { jQuery.ajaxSetup({ beforeSend: function() { - strictEqual( this.type, "GET", "no data means GET request" ); + assert.strictEqual( this.type, "GET", "no data means GET request" ); } }); jQuery("#first").load( "data/name.html", null, start ); }); // check if load can be called with url and undefined data - asyncTest( "jQuery.fn.load( String, undefined )", 2, function() { + QUnit.asyncTest( "jQuery.fn.load( String, undefined )", 2, function( assert ) { jQuery.ajaxSetup({ beforeSend: function() { - strictEqual( this.type, "GET", "no data means GET request" ); + assert.strictEqual( this.type, "GET", "no data means GET request" ); } }); jQuery("#first").load( "data/name.html", undefined, start ); }); // check if load can be called with only url - asyncTest( "jQuery.fn.load( URL_SELECTOR )", 1, function() { + QUnit.asyncTest( "jQuery.fn.load( URL_SELECTOR )", 1, function( assert ) { jQuery("#first").load( "data/test3.html div.user", function() { - strictEqual( jQuery( this ).children("div").length, 2, "Verify that specific elements were injected" ); - start(); + assert.strictEqual( jQuery( this ).children("div").length, 2, "Verify that specific elements were injected" ); + QUnit.start(); }); }); // Selector should be trimmed to avoid leading spaces (#14773) - asyncTest( "jQuery.fn.load( URL_SELECTOR with spaces )", 1, function() { + QUnit.asyncTest( "jQuery.fn.load( URL_SELECTOR with spaces )", 1, function( assert ) { jQuery("#first").load( "data/test3.html #superuser ", function() { - strictEqual( jQuery( this ).children("div").length, 1, "Verify that specific elements were injected" ); - start(); + assert.strictEqual( jQuery( this ).children("div").length, 1, "Verify that specific elements were injected" ); + QUnit.start(); }); }); - asyncTest( "jQuery.fn.load( String, Function ) - simple: inject text into DOM", 2, function() { + QUnit.asyncTest( "jQuery.fn.load( String, Function ) - simple: inject text into DOM", 2, function( assert ) { jQuery("#first").load( url("data/name.html"), function() { - ok( /^ERROR/.test(jQuery("#first").text()), "Check if content was injected into the DOM" ); - start(); + assert.ok( /^ERROR/.test(jQuery("#first").text()), "Check if content was injected into the DOM" ); + QUnit.start(); }); }); - asyncTest( "jQuery.fn.load( String, Function ) - check scripts", 7, function() { + QUnit.asyncTest( "jQuery.fn.load( String, Function ) - check scripts", 7, function( assert ) { var verifyEvaluation = function() { - strictEqual( window["testBar"], "bar", "Check if script src was evaluated after load" ); - strictEqual( jQuery("#ap").html(), "bar", "Check if script evaluation has modified DOM"); - start(); + assert.strictEqual( window["testBar"], "bar", "Check if script src was evaluated after load" ); + assert.strictEqual( jQuery("#ap").html(), "bar", "Check if script evaluation has modified DOM"); + QUnit.start(); }; Globals.register("testFoo"); Globals.register("testBar"); jQuery("#first").load( url("data/test.html"), function() { - ok( jQuery("#first").html().match( /^html text/ ), "Check content after loading html" ); - strictEqual( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM" ); - strictEqual( window["testFoo"], "foo", "Check if script was evaluated after load" ); + assert.ok( jQuery("#first").html().match( /^html text/ ), "Check content after loading html" ); + assert.strictEqual( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM" ); + assert.strictEqual( window["testFoo"], "foo", "Check if script was evaluated after load" ); setTimeout( verifyEvaluation, 600 ); }); }); - asyncTest( "jQuery.fn.load( String, Function ) - check file with only a script tag", 3, function() { + QUnit.asyncTest( "jQuery.fn.load( String, Function ) - check file with only a script tag", 3, function( assert ) { Globals.register("testFoo"); jQuery("#first").load( url("data/test2.html"), function() { - strictEqual( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM"); - strictEqual( window["testFoo"], "foo", "Check if script was evaluated after load" ); - start(); + assert.strictEqual( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM"); + assert.strictEqual( window["testFoo"], "foo", "Check if script was evaluated after load" ); + QUnit.start(); }); }); - asyncTest( "jQuery.fn.load( String, Function ) - dataFilter in ajaxSettings", 2, function() { + QUnit.asyncTest( "jQuery.fn.load( String, Function ) - dataFilter in ajaxSettings", 2, function( assert ) { jQuery.ajaxSetup({ dataFilter: function() { return "Hello World"; } }); jQuery("
").load( url("data/name.html"), function( responseText ) { - strictEqual( jQuery( this ).html(), "Hello World", "Test div was filled with filtered data" ); - strictEqual( responseText, "Hello World", "Test callback receives filtered data" ); - start(); + assert.strictEqual( jQuery( this ).html(), "Hello World", "Test div was filled with filtered data" ); + assert.strictEqual( responseText, "Hello World", "Test callback receives filtered data" ); + QUnit.start(); }); }); - asyncTest( "jQuery.fn.load( String, Object, Function )", 2, function() { + QUnit.asyncTest( "jQuery.fn.load( String, Object, Function )", 2, function( assert ) { jQuery("
").load( url("data/params_html.php"), { "foo": 3, "bar": "ok" }, function() { var $post = jQuery( this ).find("#post"); - strictEqual( $post.find("#foo").text(), "3", "Check if a hash of data is passed correctly" ); - strictEqual( $post.find("#bar").text(), "ok", "Check if a hash of data is passed correctly" ); - start(); + assert.strictEqual( $post.find("#foo").text(), "3", "Check if a hash of data is passed correctly" ); + assert.strictEqual( $post.find("#bar").text(), "ok", "Check if a hash of data is passed correctly" ); + QUnit.start(); }); }); - asyncTest( "jQuery.fn.load( String, String, Function )", 2, function() { + QUnit.test( "jQuery.fn.load( String, String, Function )", 2, function( assert ) { + var done = assert.async(); + jQuery("
").load( url("data/params_html.php"), "foo=3&bar=ok", function() { var $get = jQuery( this ).find("#get"); - strictEqual( $get.find("#foo").text(), "3", "Check if a string of data is passed correctly" ); - strictEqual( $get.find("#bar").text(), "ok", "Check if a of data is passed correctly" ); - start(); + assert.strictEqual( $get.find("#foo").text(), "3", "Check if a string of data is passed correctly" ); + assert.strictEqual( $get.find("#bar").text(), "ok", "Check if a of data is passed correctly" ); + done(); }); }); - asyncTest( "jQuery.fn.load() - callbacks get the correct parameters", 8, function() { + QUnit.test( "jQuery.fn.load() - callbacks get the correct parameters", 8, function( assert ) { var completeArgs = {}; + var done = assert.async(); jQuery.ajaxSetup({ success: function( _, status, jqXHR ) { @@ -1973,30 +2102,34 @@ module( "ajax", { return jQuery.Deferred(function( defer ) { jQuery("#foo").load( options.url, function() { var args = arguments; - strictEqual( completeArgs[ options.url ].length, args.length, "same number of arguments (" + options.type + ")" ); + assert.strictEqual( completeArgs[ options.url ].length, args.length, "same number of arguments (" + options.type + ")" ); jQuery.each( completeArgs[ options.url ], function( i, value ) { - strictEqual( args[ i ], value, "argument #" + i + " is the same (" + options.type + ")" ); + assert.strictEqual( args[ i ], value, "argument #" + i + " is the same (" + options.type + ")" ); }); defer.resolve(); }); }); }) - ).always( start ); + ).always( done ); }); - asyncTest( "#2046 - jQuery.fn.load( String, Function ) with ajaxSetup on dataType json", 1, function() { + QUnit.test( "#2046 - jQuery.fn.load( String, Function ) with ajaxSetup on dataType json", 1, function( assert ) { + var done = assert.async(); + jQuery.ajaxSetup({ dataType: "json" }); jQuery( document ).ajaxComplete(function( e, xml, s ) { - strictEqual( s.dataType, "html", "Verify the load() dataType was html" ); + assert.strictEqual( s.dataType, "html", "Verify the load() dataType was html" ); jQuery( document ).off("ajaxComplete"); - start(); + done(); }); jQuery("#first").load("data/test3.html"); }); - asyncTest( "#10524 - jQuery.fn.load() - data specified in ajaxSettings is merged in", 1, function() { + QUnit.test( "#10524 - jQuery.fn.load() - data specified in ajaxSettings is merged in", 1, function( assert ) { + var done = assert.async(); + var data = { "baz": 1 }; @@ -2007,14 +2140,16 @@ module( "ajax", { }); jQuery("#foo").load( "data/echoQuery.php", data ); jQuery( document ).ajaxComplete(function( event, jqXHR, options ) { - ok( ~options.data.indexOf("foo=bar"), "Data from ajaxSettings was used" ); - start(); + assert.ok( ~options.data.indexOf("foo=bar"), "Data from ajaxSettings was used" ); + done(); }); }); -//----------- jQuery.post() +// //----------- jQuery.post() + + QUnit.test( "jQuery.post() - data", 3, function( assert ) { + var done = assert.async(); - asyncTest( "jQuery.post() - data", 3, function() { jQuery.when( jQuery.post( url("data/name.php"), @@ -2024,8 +2159,8 @@ module( "ajax", { }, function( xml ) { jQuery( "math", xml ).each(function() { - strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" ); - strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" ); + assert.strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" ); + assert.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" ); }); } ), @@ -2039,15 +2174,17 @@ module( "ajax", { } }, success: function( data ) { - strictEqual( data, "test%5Blength%5D=7&test%5Bfoo%5D=bar", "Check if a sub-object with a length param is serialized correctly" ); + assert.strictEqual( data, "test%5Blength%5D=7&test%5Bfoo%5D=bar", "Check if a sub-object with a length param is serialized correctly" ); } }) ).always(function() { - start(); + done(); }); }); - asyncTest( "jQuery.post( String, Hash, Function ) - simple with xml", 4, function() { + QUnit.test( "jQuery.post( String, Hash, Function ) - simple with xml", 4, function( assert ) { + var done = assert.async(); + jQuery.when( jQuery.post( url("data/name.php"), @@ -2056,23 +2193,25 @@ module( "ajax", { }, function( xml ) { jQuery( "math", xml ).each(function() { - strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" ); - strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" ); + assert.strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" ); + assert.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" ); }); } ), jQuery.post( url("data/name.php?xml=5-2"), {}, function( xml ) { jQuery( "math", xml ).each(function() { - strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" ); - strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" ); + assert.strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" ); + assert.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" ); }); }) ).always(function() { - start(); + done(); }); }); - asyncTest( "jQuery[get|post]( options ) - simple with xml", 2, function() { + QUnit.test( "jQuery[get|post]( options ) - simple with xml", 2, function( assert ) { + var done = assert.async(); + jQuery.when.apply( jQuery, jQuery.map( [ "get", "post" ] , function( method ) { return jQuery[ method ]({ @@ -2082,22 +2221,21 @@ module( "ajax", { }, success: function( xml ) { jQuery( "math", xml ).each(function() { - strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" ); + assert.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" ); }); } }); }) ).always(function() { - start(); + done(); }); }); //----------- jQuery.active - test( "jQuery.active", function() { - expect( 1 ); - - ok( jQuery.active === 0, "ajax active counter should be zero: " + jQuery.active ); + QUnit.test( "jQuery.active", function( assert ) { + assert.expect( 1 ); + assert.ok( jQuery.active === 0, "ajax active counter should be zero: " + jQuery.active ); }); })(); diff --git a/test/unit/animation.js b/test/unit/animation.js index 6bb070145..3b1479432 100644 --- a/test/unit/animation.js +++ b/test/unit/animation.js @@ -11,7 +11,7 @@ var oldRaf = window.requestAnimationFrame, startTime = 505877050; // This module tests jQuery.Animation and the corresponding 1.8+ effects APIs -module( "animation", { +QUnit.module( "animation", { setup: function() { window.requestAnimationFrame = null; this.sandbox = sinon.sandbox.create(); @@ -33,77 +33,93 @@ module( "animation", { } } ); -test( "Animation( subject, props, opts ) - shape", function() { - expect( 20 ); +QUnit.test( "Animation( subject, props, opts ) - shape", function( assert ) { + assert.expect( 20 ); var subject = { test: 0 }, props = { test: 1 }, opts = { queue: "fx", duration: 100 }, animation = jQuery.Animation( subject, props, opts ); - equal( animation.elem, subject, ".elem is set to the exact object passed" ); - equal( animation.originalOptions, opts, ".originalOptions is set to options passed" ); - equal( animation.originalProperties, props, ".originalProperties is set to props passed" ); - - notEqual( animation.props, props, ".props is not the original however" ); - deepEqual( animation.props, props, ".props is a copy of the original" ); - - deepEqual( animation.opts, { + assert.equal( + animation.elem, + subject, + ".elem is set to the exact object passed" + ); + assert.equal( + animation.originalOptions, + opts, + ".originalOptions is set to options passed" + ); + assert.equal( + animation.originalProperties, + props, + ".originalProperties is set to props passed" + ); + + assert.notEqual( animation.props, props, ".props is not the original however" ); + assert.deepEqual( animation.props, props, ".props is a copy of the original" ); + + assert.deepEqual( animation.opts, { duration: 100, queue: "fx", specialEasing: { test: undefined }, easing: jQuery.easing._default }, ".options is filled with default easing and specialEasing" ); - equal( animation.startTime, startTime, "startTime was set" ); - equal( animation.duration, 100, ".duration is set" ); + assert.equal( animation.startTime, startTime, "startTime was set" ); + assert.equal( animation.duration, 100, ".duration is set" ); - equal( animation.tweens.length, 1, ".tweens has one Tween" ); - equal( typeof animation.tweens[ 0 ].run, "function", "which has a .run function" ); + assert.equal( animation.tweens.length, 1, ".tweens has one Tween" ); + assert.equal( typeof animation.tweens[ 0 ].run, "function", "which has a .run function" ); - equal( typeof animation.createTween, "function", ".createTween is a function" ); - equal( typeof animation.stop, "function", ".stop is a function" ); + assert.equal( typeof animation.createTween, "function", ".createTween is a function" ); + assert.equal( typeof animation.stop, "function", ".stop is a function" ); - equal( typeof animation.done, "function", ".done is a function" ); - equal( typeof animation.fail, "function", ".fail is a function" ); - equal( typeof animation.always, "function", ".always is a function" ); - equal( typeof animation.progress, "function", ".progress is a function" ); + assert.equal( typeof animation.done, "function", ".done is a function" ); + assert.equal( typeof animation.fail, "function", ".fail is a function" ); + assert.equal( typeof animation.always, "function", ".always is a function" ); + assert.equal( typeof animation.progress, "function", ".progress is a function" ); - equal( jQuery.timers.length, 1, "Added a timers function" ); - equal( jQuery.timers[ 0 ].elem, subject, "...with .elem as the subject" ); - equal( jQuery.timers[ 0 ].anim, animation, "...with .anim as the animation" ); - equal( jQuery.timers[ 0 ].queue, opts.queue, "...with .queue" ); + assert.equal( jQuery.timers.length, 1, "Added a timers function" ); + assert.equal( jQuery.timers[ 0 ].elem, subject, "...with .elem as the subject" ); + assert.equal( jQuery.timers[ 0 ].anim, animation, "...with .anim as the animation" ); + assert.equal( jQuery.timers[ 0 ].queue, opts.queue, "...with .queue" ); // Cleanup after ourselves by ticking to the end this.clock.tick( 100 ); } ); -test( "Animation.prefilter( fn ) - calls prefilter after defaultPrefilter", function() { - expect( 1 ); +QUnit.test( "Animation.prefilter( fn ) - calls prefilter after defaultPrefilter", + function( assert ) { + assert.expect( 1 ); - var prefilter = this.sandbox.stub(), - defaultSpy = this.sandbox.spy( jQuery.Animation.prefilters, 0 ); + var prefilter = this.sandbox.stub(), + defaultSpy = this.sandbox.spy( jQuery.Animation.prefilters, 0 ); - jQuery.Animation.prefilter( prefilter ); + jQuery.Animation.prefilter( prefilter ); - jQuery.Animation( {}, {}, {} ); - ok( prefilter.calledAfter( defaultSpy ), "our prefilter called after" ); -} ); + jQuery.Animation( {}, {}, {} ); + assert.ok( prefilter.calledAfter( defaultSpy ), "our prefilter called after" ); + } +); -test( "Animation.prefilter( fn, true ) - calls prefilter before defaultPrefilter", function() { - expect( 1 ); +QUnit.test( "Animation.prefilter( fn, true ) - calls prefilter before defaultPrefilter", + function( assert ) { + assert.expect( 1 ); - var prefilter = this.sandbox.stub(), - defaultSpy = this.sandbox.spy( jQuery.Animation.prefilters, 0 ); + var prefilter = this.sandbox.stub(), + defaultSpy = this.sandbox.spy( jQuery.Animation.prefilters, 0 ); - jQuery.Animation.prefilter( prefilter, true ); + jQuery.Animation.prefilter( prefilter, true ); - jQuery.Animation( {}, {}, {} ); - ok( prefilter.calledBefore( defaultSpy ), "our prefilter called before" ); -} ); + jQuery.Animation( {}, {}, {} ); + assert.ok( prefilter.calledBefore( defaultSpy ), "our prefilter called before" ); + } +); -test( "Animation.prefilter - prefilter return hooks", function() { - expect( 34 ); +QUnit.test( "Animation.prefilter - prefilter return hooks", function( assert ) { + assert.expect( 34 ); var animation, realAnimation, element, sandbox = this.sandbox, @@ -115,10 +131,10 @@ test( "Animation.prefilter - prefilter return hooks", function() { realAnimation = this; sandbox.spy( realAnimation, "createTween" ); - deepEqual( realAnimation.originalProperties, props, "originalProperties" ); - equal( arguments[ 0 ], this.elem, "first param elem" ); - equal( arguments[ 1 ], this.props, "second param props" ); - equal( arguments[ 2 ], this.opts, "third param opts" ); + assert.deepEqual( realAnimation.originalProperties, props, "originalProperties" ); + assert.equal( arguments[ 0 ], this.elem, "first param elem" ); + assert.equal( arguments[ 1 ], this.props, "second param props" ); + assert.equal( arguments[ 2 ], this.opts, "third param opts" ); return ourAnimation; } ), defaultSpy = sandbox.spy( jQuery.Animation.prefilters, 0 ), @@ -133,14 +149,25 @@ test( "Animation.prefilter - prefilter return hooks", function() { animation = jQuery.Animation( target, props, opts ); - equal( prefilter.callCount, 1, "Called prefilter" ); - - equal( defaultSpy.callCount, 0, - "Returning something from a prefilter caused remaining prefilters to not run" ); - equal( jQuery.fx.timer.callCount, 0, "Returning something never queues a timer" ); - equal( animation, ourAnimation, "Returning something returned it from jQuery.Animation" ); - equal( realAnimation.createTween.callCount, 0, "Returning something never creates tweens" ); - equal( TweenSpy.callCount, 0, "Returning something never creates tweens" ); + assert.equal( prefilter.callCount, 1, "Called prefilter" ); + + assert.equal( + defaultSpy.callCount, + 0, + "Returning something from a prefilter caused remaining prefilters to not run" + ); + assert.equal( jQuery.fx.timer.callCount, 0, "Returning something never queues a timer" ); + assert.equal( + animation, + ourAnimation, + "Returning something returned it from jQuery.Animation" + ); + assert.equal( + realAnimation.createTween.callCount, + 0, + "Returning something never creates tweens" + ); + assert.equal( TweenSpy.callCount, 0, "Returning something never creates tweens" ); // Test overriden usage on queues: prefilter.reset(); @@ -153,78 +180,84 @@ test( "Animation.prefilter - prefilter return hooks", function() { .animate( props, 100 ) .queue( queueSpy ); - equal( prefilter.callCount, 1, "Called prefilter" ); - equal( queueSpy.callCount, 0, "Next function in queue not called" ); + assert.equal( prefilter.callCount, 1, "Called prefilter" ); + assert.equal( queueSpy.callCount, 0, "Next function in queue not called" ); realAnimation.opts.complete.call( realAnimation.elem ); - equal( queueSpy.callCount, 1, "Next function in queue called after complete" ); + assert.equal( queueSpy.callCount, 1, "Next function in queue called after complete" ); - equal( prefilter.callCount, 2, "Called prefilter again - animation #2" ); - equal( ourAnimation.stop.callCount, 0, ".stop() on our animation hasn't been called" ); + assert.equal( prefilter.callCount, 2, "Called prefilter again - animation #2" ); + assert.equal( ourAnimation.stop.callCount, 0, ".stop() on our animation hasn't been called" ); element.stop(); - equal( ourAnimation.stop.callCount, 1, ".stop() called ourAnimation.stop()" ); - ok( !ourAnimation.stop.args[ 0 ][ 0 ], ".stop( falsy ) (undefined or false are both valid)" ); + assert.equal( ourAnimation.stop.callCount, 1, ".stop() called ourAnimation.stop()" ); + assert.ok( + !ourAnimation.stop.args[ 0 ][ 0 ], + ".stop( falsy ) (undefined or false are both valid)" + ); - equal( queueSpy.callCount, 2, "Next queue function called" ); - ok( queueSpy.calledAfter( ourAnimation.stop ), "After our animation was told to stop" ); + assert.equal( queueSpy.callCount, 2, "Next queue function called" ); + assert.ok( queueSpy.calledAfter( ourAnimation.stop ), "After our animation was told to stop" ); // ourAnimation.stop.reset(); - equal( prefilter.callCount, 3, "Got the next animation" ); + assert.equal( prefilter.callCount, 3, "Got the next animation" ); ourAnimation.stop.reset(); // do not clear queue, gotoEnd element.stop( false, true ); - ok( ourAnimation.stop.calledWith( true ), ".stop(true) calls .stop(true)" ); - ok( queueSpy.calledAfter( ourAnimation.stop ), + assert.ok( ourAnimation.stop.calledWith( true ), ".stop(true) calls .stop(true)" ); + assert.ok( queueSpy.calledAfter( ourAnimation.stop ), "and the next queue function ran after we were told" ); } ); -test( "Animation.tweener( fn ) - unshifts a * tweener", function() { - expect( 2 ); +QUnit.test( "Animation.tweener( fn ) - unshifts a * tweener", function( assert ) { + assert.expect( 2 ); var starTweeners = jQuery.Animation.tweeners[ "*" ]; jQuery.Animation.tweener( jQuery.noop ); - equal( starTweeners.length, 2 ); - deepEqual( starTweeners, [ jQuery.noop, defaultTweener ] ); + assert.equal( starTweeners.length, 2 ); + assert.deepEqual( starTweeners, [ jQuery.noop, defaultTweener ] ); } ); -test( "Animation.tweener( 'prop', fn ) - unshifts a 'prop' tweener", function() { - expect( 4 ); +QUnit.test( "Animation.tweener( 'prop', fn ) - unshifts a 'prop' tweener", function( assert ) { + assert.expect( 4 ); var tweeners = jQuery.Animation.tweeners, fn = function() {}; jQuery.Animation.tweener( "prop", jQuery.noop ); - equal( tweeners.prop.length, 1 ); - deepEqual( tweeners.prop, [ jQuery.noop ] ); + assert.equal( tweeners.prop.length, 1 ); + assert.deepEqual( tweeners.prop, [ jQuery.noop ] ); jQuery.Animation.tweener( "prop", fn ); - equal( tweeners.prop.length, 2 ); - deepEqual( tweeners.prop, [ fn, jQuery.noop ] ); + assert.equal( tweeners.prop.length, 2 ); + assert.deepEqual( tweeners.prop, [ fn, jQuery.noop ] ); } ); -test( "Animation.tweener( 'list of props', fn ) - unshifts a tweener to each prop", function() { - expect( 2 ); - var tweeners = jQuery.Animation.tweeners, - fn = function() {}; - - jQuery.Animation.tweener( "list of props", jQuery.noop ); - deepEqual( tweeners, { - list: [ jQuery.noop ], - of: [ jQuery.noop ], - props: [ jQuery.noop ], - "*": [ defaultTweener ] - } ); - - // Test with extra whitespaces - jQuery.Animation.tweener( " list\t of \tprops\n*", fn ); - deepEqual( tweeners, { - list: [ fn, jQuery.noop ], - of: [ fn, jQuery.noop ], - props: [ fn, jQuery.noop ], - "*": [ fn, defaultTweener ] - } ); -} ); +QUnit.test( + "Animation.tweener( 'list of props', fn ) - unshifts a tweener to each prop", + function( assert ) { + assert.expect( 2 ); + var tweeners = jQuery.Animation.tweeners, + fn = function() {}; + + jQuery.Animation.tweener( "list of props", jQuery.noop ); + assert.deepEqual( tweeners, { + list: [ jQuery.noop ], + of: [ jQuery.noop ], + props: [ jQuery.noop ], + "*": [ defaultTweener ] + } ); + + // Test with extra whitespaces + jQuery.Animation.tweener( " list\t of \tprops\n*", fn ); + assert.deepEqual( tweeners, { + list: [ fn, jQuery.noop ], + of: [ fn, jQuery.noop ], + props: [ fn, jQuery.noop ], + "*": [ fn, defaultTweener ] + } ); + } +); } )(); diff --git a/test/unit/attributes.js b/test/unit/attributes.js index cec7b6055..6d8848a3e 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -1,4 +1,4 @@ -module( "attributes", { +QUnit.module( "attributes", { teardown: moduleTeardown }); @@ -24,8 +24,8 @@ function functionReturningObj( value ) { Returns a function that returns the value */ -test( "jQuery.propFix integrity test", function() { - expect( 1 ); +QUnit.test( "jQuery.propFix integrity test", function( assert ) { + assert.expect( 1 ); // This must be maintained and equal jQuery.attrFix when appropriate // Ensure that accidental or erroneous property @@ -46,74 +46,74 @@ test( "jQuery.propFix integrity test", function() { "contenteditable": "contentEditable" }; - deepEqual( props, jQuery.propFix, "jQuery.propFix passes integrity check" ); + assert.deepEqual( props, jQuery.propFix, "jQuery.propFix passes integrity check" ); }); -test( "attr(String)", function() { - expect( 50 ); +QUnit.test( "attr(String)", function( assert ) { + assert.expect( 50 ); var extras, body, $body, select, optgroup, option, $img, styleElem, $button, $form, $a; - equal( jQuery("#text1").attr("type"), "text", "Check for type attribute" ); - equal( jQuery("#radio1").attr("type"), "radio", "Check for type attribute" ); - equal( jQuery("#check1").attr("type"), "checkbox", "Check for type attribute" ); - equal( jQuery("#simon1").attr("rel"), "bookmark", "Check for rel attribute" ); - equal( jQuery("#google").attr("title"), "Google!", "Check for title attribute" ); - equal( jQuery("#mark").attr("hreflang"), "en", "Check for hreflang attribute" ); - equal( jQuery("#en").attr("lang"), "en", "Check for lang attribute" ); - equal( jQuery("#simon").attr("class"), "blog link", "Check for class attribute" ); - equal( jQuery("#name").attr("name"), "name", "Check for name attribute" ); - equal( jQuery("#text1").attr("name"), "action", "Check for name attribute" ); - ok( jQuery("#form").attr("action").indexOf("formaction") >= 0, "Check for action attribute" ); - equal( jQuery("#text1").attr("value", "t").attr("value"), "t", "Check setting the value attribute" ); - equal( jQuery("#text1").attr("value", "").attr("value"), "", "Check setting the value attribute to empty string" ); - equal( jQuery("
").attr("value"), "t", "Check setting custom attr named 'value' on a div" ); - equal( jQuery("#form").attr("blah", "blah").attr("blah"), "blah", "Set non-existent attribute on a form" ); - equal( jQuery("#foo").attr("height"), undefined, "Non existent height attribute should return undefined" ); + assert.equal( jQuery("#text1").attr("type"), "text", "Check for type attribute" ); + assert.equal( jQuery("#radio1").attr("type"), "radio", "Check for type attribute" ); + assert.equal( jQuery("#check1").attr("type"), "checkbox", "Check for type attribute" ); + assert.equal( jQuery("#simon1").attr("rel"), "bookmark", "Check for rel attribute" ); + assert.equal( jQuery("#google").attr("title"), "Google!", "Check for title attribute" ); + assert.equal( jQuery("#mark").attr("hreflang"), "en", "Check for hreflang attribute" ); + assert.equal( jQuery("#en").attr("lang"), "en", "Check for lang attribute" ); + assert.equal( jQuery("#simon").attr("class"), "blog link", "Check for class attribute" ); + assert.equal( jQuery("#name").attr("name"), "name", "Check for name attribute" ); + assert.equal( jQuery("#text1").attr("name"), "action", "Check for name attribute" ); + assert.ok( jQuery("#form").attr("action").indexOf("formaction") >= 0, "Check for action attribute" ); + assert.equal( jQuery("#text1").attr("value", "t").attr("value"), "t", "Check setting the value attribute" ); + assert.equal( jQuery("#text1").attr("value", "").attr("value"), "", "Check setting the value attribute to empty string" ); + assert.equal( jQuery("
").attr("value"), "t", "Check setting custom attr named 'value' on a div" ); + assert.equal( jQuery("#form").attr("blah", "blah").attr("blah"), "blah", "Set non-existent attribute on a form" ); + assert.equal( jQuery("#foo").attr("height"), undefined, "Non existent height attribute should return undefined" ); // [7472] & [3113] (form contains an input with name="action" or name="id") extras = jQuery("").appendTo("#testForm"); - equal( jQuery("#form").attr("action","newformaction").attr("action"), "newformaction", "Check that action attribute was changed" ); - equal( jQuery("#testForm").attr("target"), undefined, "Retrieving target does not equal the input with name=target" ); - equal( jQuery("#testForm").attr("target", "newTarget").attr("target"), "newTarget", "Set target successfully on a form" ); - equal( jQuery("#testForm").removeAttr("id").attr("id"), undefined, "Retrieving id does not equal the input with name=id after id is removed [#7472]" ); + assert.equal( jQuery("#form").attr("action","newformaction").attr("action"), "newformaction", "Check that action attribute was changed" ); + assert.equal( jQuery("#testForm").attr("target"), undefined, "Retrieving target does not equal the input with name=target" ); + assert.equal( jQuery("#testForm").attr("target", "newTarget").attr("target"), "newTarget", "Set target successfully on a form" ); + assert.equal( jQuery("#testForm").removeAttr("id").attr("id"), undefined, "Retrieving id does not equal the input with name=id after id is removed [#7472]" ); // Bug #3685 (form contains input with name="name") - equal( jQuery("#testForm").attr("name"), undefined, "Retrieving name does not retrieve input with name=name" ); + assert.equal( jQuery("#testForm").attr("name"), undefined, "Retrieving name does not retrieve input with name=name" ); extras.remove(); - equal( jQuery("#text1").attr("maxlength"), "30", "Check for maxlength attribute" ); - equal( jQuery("#text1").attr("maxLength"), "30", "Check for maxLength attribute" ); - equal( jQuery("#area1").attr("maxLength"), "30", "Check for maxLength attribute" ); + assert.equal( jQuery("#text1").attr("maxlength"), "30", "Check for maxlength attribute" ); + assert.equal( jQuery("#text1").attr("maxLength"), "30", "Check for maxLength attribute" ); + assert.equal( jQuery("#area1").attr("maxLength"), "30", "Check for maxLength attribute" ); // using innerHTML in IE causes href attribute to be serialized to the full path jQuery("").attr({ "id": "tAnchor5", "href": "#5" }).appendTo("#qunit-fixture"); - equal( jQuery("#tAnchor5").attr("href"), "#5", "Check for non-absolute href (an anchor)" ); + assert.equal( jQuery("#tAnchor5").attr("href"), "#5", "Check for non-absolute href (an anchor)" ); jQuery("").appendTo("#qunit-fixture"); - equal( jQuery("#tAnchor5").prop("href"), jQuery("#tAnchor6").prop("href"), "Check for absolute href prop on an anchor" ); + assert.equal( jQuery("#tAnchor5").prop("href"), jQuery("#tAnchor6").prop("href"), "Check for absolute href prop on an anchor" ); jQuery("").appendTo("#qunit-fixture"); - equal( jQuery("#tAnchor5").prop("href"), jQuery("#scriptSrc").prop("src"), "Check for absolute src prop on a script" ); + assert.equal( jQuery("#tAnchor5").prop("href"), jQuery("#scriptSrc").prop("src"), "Check for absolute src prop on a script" ); // list attribute is readonly by default in browsers that support it jQuery("#list-test").attr( "list", "datalist" ); - equal( jQuery("#list-test").attr("list"), "datalist", "Check setting list attribute" ); + assert.equal( jQuery("#list-test").attr("list"), "datalist", "Check setting list attribute" ); // Related to [5574] and [5683] body = document.body; $body = jQuery( body ); - strictEqual( $body.attr("foo"), undefined, "Make sure that a non existent attribute returns undefined" ); + assert.strictEqual( $body.attr("foo"), undefined, "Make sure that a non existent attribute returns undefined" ); body.setAttribute( "foo", "baz" ); - equal( $body.attr("foo"), "baz", "Make sure the dom attribute is retrieved when no expando is found" ); + assert.equal( $body.attr("foo"), "baz", "Make sure the dom attribute is retrieved when no expando is found" ); $body.attr( "foo","cool" ); - equal( $body.attr("foo"), "cool", "Make sure that setting works well when both expando and dom attribute are available" ); + assert.equal( $body.attr("foo"), "cool", "Make sure that setting works well when both expando and dom attribute are available" ); body.removeAttribute("foo"); // Cleanup @@ -124,82 +124,82 @@ test( "attr(String)", function() { optgroup.appendChild( option ); select.appendChild( optgroup ); - equal( jQuery( option ).prop("selected"), true, "Make sure that a single option is selected, even when in an optgroup." ); + assert.equal( jQuery( option ).prop("selected"), true, "Make sure that a single option is selected, even when in an optgroup." ); $img = jQuery("").appendTo("body"); - equal( $img.attr("width"), "215", "Retrieve width attribute an an element with display:none." ); - equal( $img.attr("height"), "53", "Retrieve height attribute an an element with display:none." ); + assert.equal( $img.attr("width"), "215", "Retrieve width attribute an an element with display:none." ); + assert.equal( $img.attr("height"), "53", "Retrieve height attribute an an element with display:none." ); // Check for style support styleElem = jQuery("
").appendTo("#qunit-fixture").css({ background: "url(UPPERlower.gif)" }); - ok( !!~styleElem.attr("style").indexOf("UPPERlower.gif"), "Check style attribute getter" ); - ok( !!~styleElem.attr("style", "position:absolute;").attr("style").indexOf("absolute"), "Check style setter" ); + assert.ok( !!~styleElem.attr("style").indexOf("UPPERlower.gif"), "Check style attribute getter" ); + assert.ok( !!~styleElem.attr("style", "position:absolute;").attr("style").indexOf("absolute"), "Check style setter" ); // Check value on button element (#1954) $button = jQuery("").insertAfter("#button"); - strictEqual( $button.attr("value"), undefined, "Absence of value attribute on a button" ); - equal( $button.attr( "value", "foobar" ).attr("value"), "foobar", "Value attribute on a button does not return innerHTML" ); - equal( $button.attr("value", "baz").html(), "text", "Setting the value attribute does not change innerHTML" ); + assert.strictEqual( $button.attr("value"), undefined, "Absence of value attribute on a button" ); + assert.equal( $button.attr( "value", "foobar" ).attr("value"), "foobar", "Value attribute on a button does not return innerHTML" ); + assert.equal( $button.attr("value", "baz").html(), "text", "Setting the value attribute does not change innerHTML" ); // Attributes with a colon on a table element (#1591) - equal( jQuery("#table").attr("test:attrib"), undefined, "Retrieving a non-existent attribute on a table with a colon does not throw an error." ); - equal( jQuery("#table").attr( "test:attrib", "foobar" ).attr("test:attrib"), "foobar", "Setting an attribute on a table with a colon does not throw an error." ); + assert.equal( jQuery("#table").attr("test:attrib"), undefined, "Retrieving a non-existent attribute on a table with a colon does not throw an error." ); + assert.equal( jQuery("#table").attr( "test:attrib", "foobar" ).attr("test:attrib"), "foobar", "Setting an attribute on a table with a colon does not throw an error." ); $form = jQuery("
").appendTo("#qunit-fixture"); - equal( $form.attr("class"), "something", "Retrieve the class attribute on a form." ); + assert.equal( $form.attr("class"), "something", "Retrieve the class attribute on a form." ); $a = jQuery("
Click").appendTo("#qunit-fixture"); - equal( $a.attr("onclick"), "something()", "Retrieve ^on attribute without anonymous function wrapper." ); + assert.equal( $a.attr("onclick"), "something()", "Retrieve ^on attribute without anonymous function wrapper." ); - ok( jQuery("
").attr("doesntexist") === undefined, "Make sure undefined is returned when no attribute is found." ); - ok( jQuery("
").attr("title") === undefined, "Make sure undefined is returned when no attribute is found." ); - equal( jQuery("
").attr( "title", "something" ).attr("title"), "something", "Set the title attribute." ); - ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." ); - equal( jQuery("
").attr("value"), undefined, "An unset value on a div returns undefined." ); - strictEqual( jQuery("").attr("value"), undefined, "An unset value on a select returns undefined." ); + assert.ok( jQuery("
").attr("doesntexist") === undefined, "Make sure undefined is returned when no attribute is found." ); + assert.ok( jQuery("
").attr("title") === undefined, "Make sure undefined is returned when no attribute is found." ); + assert.equal( jQuery("
").attr( "title", "something" ).attr("title"), "something", "Set the title attribute." ); + assert.ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." ); + assert.equal( jQuery("
").attr("value"), undefined, "An unset value on a div returns undefined." ); + assert.strictEqual( jQuery("").attr("value"), undefined, "An unset value on a select returns undefined." ); $form = jQuery("#form").attr( "enctype", "multipart/form-data" ); - equal( $form.prop("enctype"), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" ); + assert.equal( $form.prop("enctype"), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" ); }); -test( "attr(String) on cloned elements, #9646", function() { - expect( 4 ); +QUnit.test( "attr(String) on cloned elements, #9646", function( assert ) { + assert.expect( 4 ); var div, input = jQuery(""); input.attr("name"); - strictEqual( input.clone( true ).attr( "name", "test" )[ 0 ].name, "test", "Name attribute should be changed on cloned element" ); + assert.strictEqual( input.clone( true ).attr( "name", "test" )[ 0 ].name, "test", "Name attribute should be changed on cloned element" ); div = jQuery("
"); div.attr("id"); - strictEqual( div.clone( true ).attr( "id", "test" )[ 0 ].id, "test", "Id attribute should be changed on cloned element" ); + assert.strictEqual( div.clone( true ).attr( "id", "test" )[ 0 ].id, "test", "Id attribute should be changed on cloned element" ); input = jQuery(""); input.attr("value"); - strictEqual( input.clone( true ).attr( "value", "test" )[ 0 ].value, "test", "Value attribute should be changed on cloned element" ); + assert.strictEqual( input.clone( true ).attr( "value", "test" )[ 0 ].value, "test", "Value attribute should be changed on cloned element" ); - strictEqual( input.clone( true ).attr( "value", 42 )[ 0 ].value, "42", "Value attribute should be changed on cloned element" ); + assert.strictEqual( input.clone( true ).attr( "value", 42 )[ 0 ].value, "42", "Value attribute should be changed on cloned element" ); }); -test( "attr(String) in XML Files", function() { - expect( 3 ); +QUnit.test( "attr(String) in XML Files", function( assert ) { + assert.expect( 3 ); var xml = createDashboardXML(); - equal( jQuery( "locations", xml ).attr("class"), "foo", "Check class attribute in XML document" ); - equal( jQuery( "location", xml ).attr("for"), "bar", "Check for attribute in XML document" ); - equal( jQuery( "location", xml ).attr("checked"), "different", "Check that hooks are not attached in XML document" ); + assert.equal( jQuery( "locations", xml ).attr("class"), "foo", "Check class attribute in XML document" ); + assert.equal( jQuery( "location", xml ).attr("for"), "bar", "Check for attribute in XML document" ); + assert.equal( jQuery( "location", xml ).attr("checked"), "different", "Check that hooks are not attached in XML document" ); }); -test( "attr(String, Function)", function() { - expect( 2 ); +QUnit.test( "attr(String, Function)", function( assert ) { + assert.expect( 2 ); - equal( + assert.equal( jQuery("#text1").attr( "value", function() { return this.id; }).attr("value"), @@ -207,7 +207,7 @@ test( "attr(String, Function)", function() { "Set value from id" ); - equal( + assert.equal( jQuery("#text1").attr( "title", function(i) { return i; }).attr("title"), @@ -216,8 +216,8 @@ test( "attr(String, Function)", function() { ); }); -test( "attr(Hash)", function() { - expect( 3 ); +QUnit.test( "attr(Hash)", function( assert ) { + assert.expect( 3 ); var pass = true; jQuery("div").attr({ "foo": "baz", @@ -228,9 +228,9 @@ test( "attr(Hash)", function() { } }); - ok( pass, "Set Multiple Attributes" ); + assert.ok( pass, "Set Multiple Attributes" ); - equal( + assert.equal( jQuery("#text1").attr({ "value": function() { return this["id"]; @@ -239,7 +239,7 @@ test( "attr(Hash)", function() { "Set attribute to computed value #1" ); - equal( + assert.equal( jQuery("#text1").attr({ "title": function(i) { return i; @@ -250,8 +250,8 @@ test( "attr(Hash)", function() { ); }); -test( "attr(String, Object)", function() { - expect( 71 ); +QUnit.test( "attr(String, Object)", function( assert ) { + assert.expect( 71 ); var $input, $text, $details, attributeNode, commentNode, textNode, obj, @@ -268,9 +268,9 @@ test( "attr(String, Object)", function() { } } - equal( fail, false, "Set Attribute, the #" + fail + " element didn't get the attribute 'foo'" ); + assert.equal( fail, false, "Set Attribute, the #" + fail + " element didn't get the attribute 'foo'" ); - ok( + assert.ok( jQuery("#foo").attr({ "width": null }), @@ -278,90 +278,90 @@ test( "attr(String, Object)", function() { ); jQuery("#name").attr( "name", "something" ); - equal( jQuery("#name").attr("name"), "something", "Set name attribute" ); + assert.equal( jQuery("#name").attr("name"), "something", "Set name attribute" ); jQuery("#name").attr( "name", null ); - equal( jQuery("#name").attr("name"), undefined, "Remove name attribute" ); + assert.equal( jQuery("#name").attr("name"), undefined, "Remove name attribute" ); $input = jQuery( "", { name: "something", id: "specified" }); - equal( $input.attr("name"), "something", "Check element creation gets/sets the name attribute." ); - equal( $input.attr("id"), "specified", "Check element creation gets/sets the id attribute." ); + assert.equal( $input.attr("name"), "something", "Check element creation gets/sets the name attribute." ); + assert.equal( $input.attr("id"), "specified", "Check element creation gets/sets the id attribute." ); // As of fixing #11115, we only guarantee boolean property update for checked and selected $input = jQuery("").attr( "checked", true ); - equal( $input.prop("checked"), true, "Setting checked updates property (verified by .prop)" ); - equal( $input[0].checked, true, "Setting checked updates property (verified by native property)" ); + assert.equal( $input.prop("checked"), true, "Setting checked updates property (verified by .prop)" ); + assert.equal( $input[0].checked, true, "Setting checked updates property (verified by native property)" ); $input = jQuery("