forked from jquery/jquery-migrate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajax.js
121 lines (103 loc) · 2.94 KB
/
ajax.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Support jQuery slim which excludes the ajax module
if ( jQuery.ajax ) {
QUnit.module( "ajax" );
QUnit.test( "jQuery.ajax() deprecations on jqXHR", function( assert ) {
assert.expect( 3 );
var done = assert.async();
expectWarning( assert, ".success(), .error(), .complete() calls", 3, function() {
return jQuery.ajax( url( "not-found.404" ) )
.success( jQuery.noop )
.error( function( jQXHR ) {
// Local file errors returns 0, pretend it's a 404
assert.equal( jQXHR.status || 404, 404, "ajax error" );
} )
.complete( function() {
assert.ok( true, "ajax complete" );
} )[ "catch" ]( jQuery.noop );
} ).then( function() {
done();
} );
} );
[ " - Same Domain", " - Cross Domain" ].forEach( function( label, crossDomain ) {
// The JSON-to-JSONP auto-promotion behavior is gone in jQuery 4.0 and as
// it has security implications, we don't want to restore the legacy behavior.
QUnit[ jQueryVersionSince( "4.0.0" ) ? "skip" : "test" ](
"jQuery.ajax() JSON-to-JSONP auto-promotion" + label, function( assert ) {
assert.expect( 5 );
var done = assert.async(),
tests = [
function() {
return expectNoWarning( assert, "dataType: \"json\"",
function() {
return jQuery.ajax( {
url: url( "null.json" ),
crossDomain: crossDomain,
dataType: "json"
} )[ "catch" ]( jQuery.noop );
}
);
},
function() {
return expectWarning( assert, "dataType: \"json\", URL callback", 1,
function() {
return jQuery.ajax( {
url: url( "null.json?callback=?" ),
crossDomain: crossDomain,
dataType: "json"
} )[ "catch" ]( jQuery.noop );
}
);
},
function() {
return expectWarning( assert, "dataType: \"json\", data callback", 1,
function() {
return jQuery.ajax( {
url: url( "null.json" ),
crossDomain: crossDomain,
data: "callback=?",
dataType: "json"
} )[ "catch" ]( jQuery.noop );
}
);
},
function() {
return expectNoWarning( assert, "dataType: \"jsonp\", URL callback",
function() {
return jQuery.ajax( {
url: url( "null.json?callback=?" ),
crossDomain: crossDomain,
dataType: "jsonp"
} )[ "catch" ]( jQuery.noop );
}
);
},
function() {
return expectNoWarning( assert, "dataType: \"jsonp\", data callback",
function() {
return jQuery.ajax( {
url: url( "null.json" ),
crossDomain: crossDomain,
data: "callback=?",
dataType: "jsonp"
} )[ "catch" ]( jQuery.noop );
}
);
}
];
// Invoke tests sequentially as they're async and early tests could get warnings
// from later ones.
function run( tests ) {
var test = tests[ 0 ];
return test().then( function() {
if ( tests.length > 1 ) {
return run( tests.slice( 1 ) );
}
} );
}
run( tests )
.then( function() {
done();
} );
} );
} );
}