aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/ajax.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/ajax.js')
-rw-r--r--test/unit/ajax.js195
1 files changed, 127 insertions, 68 deletions
diff --git a/test/unit/ajax.js b/test/unit/ajax.js
index 3defc0ea8..35f7bba6b 100644
--- a/test/unit/ajax.js
+++ b/test/unit/ajax.js
@@ -1,5 +1,5 @@
QUnit.module( "ajax", {
- teardown: function() {
+ afterEach: function() {
jQuery( document ).off( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess" );
moduleTeardown.apply( this, arguments );
}
@@ -221,9 +221,11 @@ QUnit.module( "ajax", {
};
} );
- QUnit.asyncTest( "jQuery.ajax() - retry with jQuery.ajax( this )", 2, function( assert ) {
+ QUnit.test( "jQuery.ajax() - retry with jQuery.ajax( this )", function( assert ) {
+ assert.expect( 2 );
var previousUrl,
- firstTime = true;
+ firstTime = true,
+ done = assert.async();
jQuery.ajax( {
url: url( "mock.php?action=error" ),
error: function() {
@@ -239,7 +241,7 @@ QUnit.module( "ajax", {
previousUrl = this.url;
} else {
assert.strictEqual( this.url, previousUrl, "url parameters are not re-appended" );
- QUnit.start();
+ done();
return false;
}
},
@@ -856,7 +858,9 @@ QUnit.module( "ajax", {
};
} );
- QUnit.asyncTest( "jQuery.ajax(), jQuery.get[Script|JSON](), jQuery.post(), pass-through request object", 8, function( assert ) {
+ QUnit.test( "jQuery.ajax(), jQuery.get[Script|JSON](), jQuery.post(), pass-through request object", function( assert ) {
+ assert.expect( 8 );
+ var done = assert.async();
var target = "name.html",
successCount = 0,
errorCount = 0,
@@ -872,7 +876,7 @@ QUnit.module( "ajax", {
assert.equal( successCount, 5, "Check all ajax calls successful" );
assert.equal( errorCount, 0, "Check no ajax errors (status" + errorEx + ")" );
jQuery( document ).off( "ajaxError.passthru" );
- QUnit.start();
+ done();
} );
Globals.register( "testBar" );
@@ -1376,7 +1380,9 @@ QUnit.module( "ajax", {
},
function( type, url ) {
url = baseURL + url + "&ts=" + ifModifiedNow++;
- QUnit.asyncTest( "jQuery.ajax() - " + type + " support" + label, 4, function( assert ) {
+ QUnit.test( "jQuery.ajax() - " + type + " support" + label, function( assert ) {
+ assert.expect( 4 );
+ var done = assert.async();
jQuery.ajax( {
url: url,
ifModified: true,
@@ -1393,7 +1399,7 @@ QUnit.module( "ajax", {
assert.equal( data, null, "no response body is given" );
},
complete: function() {
- QUnit.start();
+ done();
}
} );
}
@@ -1434,24 +1440,27 @@ QUnit.module( "ajax", {
};
} );
- QUnit.asyncTest( "jQuery.ajax() - statusText", 3, function( assert ) {
+ QUnit.test( "jQuery.ajax() - statusText", function( assert ) {
+ assert.expect( 3 );
+ var done = assert.async();
jQuery.ajax( url( "mock.php?action=status&code=200&text=Hello" ) ).done( function( _, statusText, jqXHR ) {
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( "mock.php?action=status&code=404&text=World" ) ).fail( function( jqXHR, statusText ) {
assert.strictEqual( statusText, "error", "callback status text ok for error" );
- QUnit.start();
+ done();
} );
} );
} );
- QUnit.asyncTest( "jQuery.ajax() - statusCode", 20, function( assert ) {
-
- var count = 12;
+ QUnit.test( "jQuery.ajax() - statusCode", function( assert ) {
+ assert.expect( 20 );
+ var done = assert.async(),
+ count = 12;
function countComplete() {
if ( !--count ) {
- QUnit.start();
+ done();
}
}
@@ -1853,12 +1862,14 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} );
}
- QUnit.asyncTest( "#11743 - jQuery.ajax() - script, throws exception", 1, function( assert ) {
+ QUnit.test( "#11743 - jQuery.ajax() - script, throws exception", function( assert ) {
+ assert.expect( 1 );
+ var done = assert.async();
var onerror = window.onerror;
window.onerror = function() {
assert.ok( true, "Exception thrown" );
window.onerror = onerror;
- QUnit.start();
+ done();
};
jQuery.ajax( {
url: baseURL + "badjson.js",
@@ -2148,29 +2159,33 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
//----------- jQuery.ajaxSetup()
- QUnit.asyncTest( "jQuery.ajaxSetup()", 1, function( assert ) {
+ QUnit.test( "jQuery.ajaxSetup()", function( assert ) {
+ assert.expect( 1 );
+ var done = assert.async();
jQuery.ajaxSetup( {
url: url( "mock.php?action=name&name=foo" ),
success: function( msg ) {
assert.strictEqual( msg, "bar", "Check for GET" );
- QUnit.start();
+ done();
}
} );
jQuery.ajax();
} );
- QUnit.asyncTest( "jQuery.ajaxSetup({ timeout: Number }) - with global timeout", 2, function( assert ) {
+ QUnit.test( "jQuery.ajaxSetup({ timeout: Number }) - with global timeout", function( assert ) {
+ assert.expect( 2 );
+ var done = assert.async();
var passed = 0,
pass = function() {
assert.ok( passed++ < 2, "Error callback executed" );
if ( passed === 2 ) {
jQuery( document ).off( "ajaxError.setupTest" );
- QUnit.start();
+ done();
}
},
fail = function( a, b ) {
assert.ok( false, "Check for timeout failed " + a + " " + b );
- QUnit.start();
+ done();
};
jQuery( document ).on( "ajaxError.setupTest", pass );
@@ -2187,7 +2202,9 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} );
} );
- QUnit.asyncTest( "jQuery.ajaxSetup({ timeout: Number }) with localtimeout", 1, function( assert ) {
+ QUnit.test( "jQuery.ajaxSetup({ timeout: Number }) with localtimeout", function( assert ) {
+ assert.expect( 1 );
+ var done = assert.async();
jQuery.ajaxSetup( {
timeout: 50
} );
@@ -2197,11 +2214,11 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
url: url( "mock.php?action=wait&wait=1" ),
error: function() {
assert.ok( false, "Check for local timeout failed" );
- QUnit.start();
+ done();
},
success: function() {
assert.ok( true, "Check for local timeout" );
- QUnit.start();
+ done();
}
} );
} );
@@ -2225,8 +2242,9 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} );
QUnit.test(
- "jQuery#load() - always use GET method even if it overrided through ajaxSetup (#11264)", 1,
+ "jQuery#load() - always use GET method even if it overrided through ajaxSetup (#11264)",
function( assert ) {
+ assert.expect( 1 );
var done = assert.async();
jQuery.ajaxSetup( {
@@ -2241,8 +2259,9 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
);
QUnit.test(
- "jQuery#load() - should resolve with correct context", 2,
+ "jQuery#load() - should resolve with correct context",
function( assert ) {
+ assert.expect( 2 );
var done = assert.async();
var ps = jQuery( "<p></p><p></p>" );
var i = 0;
@@ -2260,15 +2279,18 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
);
QUnit.test(
- "#11402 - jQuery.domManip() - script in comments are properly evaluated", 2,
+ "#11402 - jQuery.domManip() - script in comments are properly evaluated",
function( assert ) {
+ assert.expect( 2 );
jQuery( "#qunit-fixture" ).load( baseURL + "cleanScript.html", assert.async() );
}
);
//----------- jQuery.get()
- QUnit.asyncTest( "jQuery.get( String, Hash, Function ) - parse xml and use text() on nodes", 2, function( assert ) {
+ QUnit.test( "jQuery.get( String, Hash, Function ) - parse xml and use text() on nodes", function( assert ) {
+ assert.expect( 2 );
+ var done = assert.async();
jQuery.get( url( "dashboard.xml" ), function( xml ) {
var content = [];
jQuery( "tab", xml ).each( function() {
@@ -2276,23 +2298,27 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} );
assert.strictEqual( content[ 0 ], "blabla", "Check first tab" );
assert.strictEqual( content[ 1 ], "blublu", "Check second tab" );
- QUnit.start();
+ done();
} );
} );
- QUnit.asyncTest( "#8277 - jQuery.get( String, Function ) - data in ajaxSettings", 1, function( assert ) {
+ QUnit.test( "#8277 - jQuery.get( String, Function ) - data in ajaxSettings", function( assert ) {
+ assert.expect( 1 );
+ var done = assert.async();
jQuery.ajaxSetup( {
data: "helloworld"
} );
jQuery.get( url( "mock.php?action=echoQuery" ), function( data ) {
assert.ok( /helloworld$/.test( data ), "Data from ajaxSettings was used" );
- QUnit.start();
+ done();
} );
} );
//----------- jQuery.getJSON()
- QUnit.asyncTest( "jQuery.getJSON( String, Hash, Function ) - JSON array", 5, function( assert ) {
+ QUnit.test( "jQuery.getJSON( String, Hash, Function ) - JSON array", function( assert ) {
+ assert.expect( 5 );
+ var done = assert.async();
jQuery.getJSON(
url( "mock.php?action=json" ),
{
@@ -2304,22 +2330,26 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
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();
+ done();
}
);
} );
- QUnit.asyncTest( "jQuery.getJSON( String, Function ) - JSON object", 2, function( assert ) {
+ QUnit.test( "jQuery.getJSON( String, Function ) - JSON object", function( assert ) {
+ assert.expect( 2 );
+ var done = assert.async();
jQuery.getJSON( url( "mock.php?action=json" ), function( json ) {
if ( json && json[ "data" ] ) {
assert.strictEqual( json[ "data" ][ "lang" ], "en", "Check JSON: lang" );
assert.strictEqual( json[ "data" ].length, 25, "Check JSON: length" );
- QUnit.start();
+ done();
}
} );
} );
- QUnit.asyncTest( "jQuery.getJSON( String, Function ) - JSON object with absolute url to local content", 2, function( assert ) {
+ QUnit.test( "jQuery.getJSON( String, Function ) - JSON object with absolute url to local content", function( assert ) {
+ assert.expect( 2 );
+ var done = assert.async();
var absoluteUrl = url( "mock.php?action=json" );
// Make a relative URL absolute relative to the document location
@@ -2338,14 +2368,15 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
jQuery.getJSON( absoluteUrl, function( json ) {
assert.strictEqual( json.data.lang, "en", "Check JSON: lang" );
assert.strictEqual( json.data.length, 25, "Check JSON: length" );
- QUnit.start();
+ done();
} );
} );
//----------- jQuery.getScript()
- QUnit.test( "jQuery.getScript( String, Function ) - with callback", 2,
+ QUnit.test( "jQuery.getScript( String, Function ) - with callback",
function( assert ) {
+ assert.expect( 2 );
var done = assert.async();
Globals.register( "testBar" );
@@ -2356,12 +2387,14 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
}
);
- QUnit.test( "jQuery.getScript( String, Function ) - no callback", 1, function( assert ) {
+ QUnit.test( "jQuery.getScript( String, Function ) - no callback", function( assert ) {
+ assert.expect( 1 );
Globals.register( "testBar" );
jQuery.getScript( url( "mock.php?action=testbar" ) ).done( assert.async() );
} );
- QUnit.test( "#8082 - jQuery.getScript( String, Function ) - source as responseText", 2, function( assert ) {
+ QUnit.test( "#8082 - jQuery.getScript( String, Function ) - source as responseText", function( assert ) {
+ assert.expect( 2 );
var done = assert.async();
Globals.register( "testBar" );
@@ -2371,7 +2404,8 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} );
} );
- QUnit.test( "jQuery.getScript( Object ) - with callback", 2, function( assert ) {
+ QUnit.test( "jQuery.getScript( Object ) - with callback", function( assert ) {
+ assert.expect( 2 );
var done = assert.async();
Globals.register( "testBar" );
@@ -2384,7 +2418,8 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} );
} );
- QUnit.test( "jQuery.getScript( Object ) - no callback", 1, function( assert ) {
+ QUnit.test( "jQuery.getScript( Object ) - no callback", function( assert ) {
+ assert.expect( 1 );
Globals.register( "testBar" );
jQuery.getScript( { url: url( "mock.php?action=testbar" ) } ).done( assert.async() );
} );
@@ -2392,7 +2427,8 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
// //----------- jQuery.fn.load()
// check if load can be called with only url
- QUnit.test( "jQuery.fn.load( String )", 2, function( assert ) {
+ QUnit.test( "jQuery.fn.load( String )", function( assert ) {
+ assert.expect( 2 );
jQuery.ajaxSetup( {
beforeSend: function() {
assert.strictEqual( this.type, "GET", "no data means GET request" );
@@ -2413,7 +2449,8 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} );
// check if load can be called with url and null data
- QUnit.test( "jQuery.fn.load( String, null )", 2, function( assert ) {
+ QUnit.test( "jQuery.fn.load( String, null )", function( assert ) {
+ assert.expect( 2 );
jQuery.ajaxSetup( {
beforeSend: function() {
assert.strictEqual( this.type, "GET", "no data means GET request" );
@@ -2423,7 +2460,8 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} );
// check if load can be called with url and undefined data
- QUnit.test( "jQuery.fn.load( String, undefined )", 2, function( assert ) {
+ QUnit.test( "jQuery.fn.load( String, undefined )", function( assert ) {
+ assert.expect( 2 );
jQuery.ajaxSetup( {
beforeSend: function() {
assert.strictEqual( this.type, "GET", "no data means GET request" );
@@ -2433,18 +2471,22 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} );
// check if load can be called with only url
- QUnit.asyncTest( "jQuery.fn.load( URL_SELECTOR )", 1, function( assert ) {
+ QUnit.test( "jQuery.fn.load( URL_SELECTOR )", function( assert ) {
+ assert.expect( 1 );
+ var done = assert.async();
jQuery( "#first" ).load( baseURL + "test3.html div.user", function() {
assert.strictEqual( jQuery( this ).children( "div" ).length, 2, "Verify that specific elements were injected" );
- QUnit.start();
+ done();
} );
} );
// Selector should be trimmed to avoid leading spaces (#14773)
- QUnit.asyncTest( "jQuery.fn.load( URL_SELECTOR with spaces )", 1, function( assert ) {
+ QUnit.test( "jQuery.fn.load( URL_SELECTOR with spaces )", function( assert ) {
+ assert.expect( 1 );
+ var done = assert.async();
jQuery( "#first" ).load( baseURL + "test3.html #superuser ", function() {
assert.strictEqual( jQuery( this ).children( "div" ).length, 1, "Verify that specific elements were injected" );
- QUnit.start();
+ done();
} );
} );
@@ -2459,18 +2501,22 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} );
} );
- QUnit.asyncTest( "jQuery.fn.load( String, Function ) - simple: inject text into DOM", 2, function( assert ) {
+ QUnit.test( "jQuery.fn.load( String, Function ) - simple: inject text into DOM", function( assert ) {
+ assert.expect( 2 );
+ var done = assert.async();
jQuery( "#first" ).load( url( "name.html" ), function() {
assert.ok( /^ERROR/.test( jQuery( "#first" ).text() ), "Check if content was injected into the DOM" );
- QUnit.start();
+ done();
} );
} );
- QUnit.asyncTest( "jQuery.fn.load( String, Function ) - check scripts", 7, function( assert ) {
+ QUnit.test( "jQuery.fn.load( String, Function ) - check scripts", function( assert ) {
+ assert.expect( 7 );
+ var done = assert.async();
var verifyEvaluation = function() {
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();
+ done();
};
Globals.register( "testFoo" );
@@ -2484,17 +2530,21 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} );
} );
- QUnit.asyncTest( "jQuery.fn.load( String, Function ) - check file with only a script tag", 3, function( assert ) {
+ QUnit.test( "jQuery.fn.load( String, Function ) - check file with only a script tag", function( assert ) {
+ assert.expect( 3 );
+ var done = assert.async();
Globals.register( "testFoo" );
jQuery( "#first" ).load( url( "test2.html" ), function() {
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();
+ done();
} );
} );
- QUnit.asyncTest( "jQuery.fn.load( String, Function ) - dataFilter in ajaxSettings", 2, function( assert ) {
+ QUnit.test( "jQuery.fn.load( String, Function ) - dataFilter in ajaxSettings", function( assert ) {
+ assert.expect( 2 );
+ var done = assert.async();
jQuery.ajaxSetup( {
dataFilter: function() {
return "Hello World";
@@ -2503,22 +2553,25 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
jQuery( "<div/>" ).load( url( "name.html" ), function( responseText ) {
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();
+ done();
} );
} );
- QUnit.asyncTest( "jQuery.fn.load( String, Object, Function )", 2, function( assert ) {
+ QUnit.test( "jQuery.fn.load( String, Object, Function )", function( assert ) {
+ assert.expect( 2 );
+ var done = assert.async();
jQuery( "<div />" ).load( url( "mock.php?action=echoHtml" ), {
"bar": "ok"
}, function() {
var $node = jQuery( this );
assert.strictEqual( $node.find( "#method" ).text(), "POST", "Check method" );
assert.strictEqual( $node.find( "#data" ).text(), "bar=ok", "Check if data is passed correctly" );
- QUnit.start();
+ done();
} );
} );
- QUnit.test( "jQuery.fn.load( String, String, Function )", 2, function( assert ) {
+ QUnit.test( "jQuery.fn.load( String, String, Function )", function( assert ) {
+ assert.expect( 2 );
var done = assert.async();
jQuery( "<div />" ).load( url( "mock.php?action=echoHtml" ), "foo=3&bar=ok", function() {
@@ -2529,9 +2582,10 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} );
} );
- QUnit.test( "jQuery.fn.load() - callbacks get the correct parameters", 8, function( assert ) {
- var completeArgs = {};
- var done = assert.async();
+ QUnit.test( "jQuery.fn.load() - callbacks get the correct parameters", function( assert ) {
+ assert.expect( 8 );
+ var completeArgs = {},
+ done = assert.async();
jQuery.ajaxSetup( {
success: function( _, status, jqXHR ) {
@@ -2569,7 +2623,8 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
).always( done );
} );
- QUnit.test( "#2046 - jQuery.fn.load( String, Function ) with ajaxSetup on dataType json", 1, function( assert ) {
+ QUnit.test( "#2046 - jQuery.fn.load( String, Function ) with ajaxSetup on dataType json", function( assert ) {
+ assert.expect( 1 );
var done = assert.async();
jQuery.ajaxSetup( {
@@ -2583,7 +2638,8 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
jQuery( "#first" ).load( baseURL + "test3.html" );
} );
- QUnit.test( "#10524 - jQuery.fn.load() - data specified in ajaxSettings is merged in", 1, function( assert ) {
+ QUnit.test( "#10524 - jQuery.fn.load() - data specified in ajaxSettings is merged in", function( assert ) {
+ assert.expect( 1 );
var done = assert.async();
var data = {
@@ -2603,7 +2659,8 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
// //----------- jQuery.post()
- QUnit.test( "jQuery.post() - data", 3, function( assert ) {
+ QUnit.test( "jQuery.post() - data", function( assert ) {
+ assert.expect( 3 );
var done = assert.async();
jQuery.when(
@@ -2635,7 +2692,8 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
).always( done );
} );
- QUnit.test( "jQuery.post( String, Hash, Function ) - simple with xml", 4, function( assert ) {
+ QUnit.test( "jQuery.post( String, Hash, Function ) - simple with xml", function( assert ) {
+ assert.expect( 4 );
var done = assert.async();
jQuery.when(
@@ -2662,7 +2720,8 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} );
} );
- QUnit.test( "jQuery[get|post]( options ) - simple with xml", 2, function( assert ) {
+ QUnit.test( "jQuery[get|post]( options ) - simple with xml", function( assert ) {
+ assert.expect( 2 );
var done = assert.async();
jQuery.when.apply( jQuery,