aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/ajax.js
diff options
context:
space:
mode:
authorRichard Gibson <richard.gibson@gmail.com>2018-09-07 10:14:01 -0400
committerGitHub <noreply@github.com>2018-09-07 10:14:01 -0400
commitdfa92ccead70d7dd5735a36c6d0dd1af680271cd (patch)
tree95d7500d4ddcc944f3d388216c0c6bec211461d2 /test/unit/ajax.js
parentf997241f0011ed728be71002bc703c7a0d3f01e5 (diff)
downloadjquery-dfa92ccead70d7dd5735a36c6d0dd1af680271cd.tar.gz
jquery-dfa92ccead70d7dd5735a36c6d0dd1af680271cd.zip
Tests: Allow Karma to load unminfied source
Closes gh-4128
Diffstat (limited to 'test/unit/ajax.js')
-rw-r--r--test/unit/ajax.js41
1 files changed, 30 insertions, 11 deletions
diff --git a/test/unit/ajax.js b/test/unit/ajax.js
index 72a4e7215..b8b46e245 100644
--- a/test/unit/ajax.js
+++ b/test/unit/ajax.js
@@ -345,12 +345,13 @@ QUnit.module( "ajax", {
};
} );
- ajaxTest( "jQuery.ajax() - hash", 4, function( assert ) {
+ ajaxTest( "jQuery.ajax() - URL fragment component preservation", 4, function( assert ) {
return [
{
url: baseURL + "name.html#foo",
beforeSend: function( xhr, settings ) {
- assert.equal( settings.url, baseURL + "name.html#foo", "Make sure that the URL has its hash." );
+ assert.equal( settings.url, baseURL + "name.html#foo",
+ "hash preserved for request with no query component." );
return false;
},
error: true
@@ -358,7 +359,8 @@ QUnit.module( "ajax", {
{
url: baseURL + "name.html?abc#foo",
beforeSend: function( xhr, settings ) {
- assert.equal( settings.url, baseURL + "name.html?abc#foo", "Make sure that the URL has its hash." );
+ assert.equal( settings.url, baseURL + "name.html?abc#foo",
+ "hash preserved for request with query component." );
return false;
},
error: true
@@ -369,7 +371,8 @@ QUnit.module( "ajax", {
"test": 123
},
beforeSend: function( xhr, settings ) {
- assert.equal( settings.url, baseURL + "name.html?abc&test=123#foo", "Make sure that the URL has its hash." );
+ assert.equal( settings.url, baseURL + "name.html?abc&test=123#foo",
+ "hash preserved for request with query component and data." );
return false;
},
error: true
@@ -381,9 +384,10 @@ QUnit.module( "ajax", {
},
cache: false,
beforeSend: function( xhr, settings ) {
- // Remove the random number, but ensure the cache-buster param is there
- var url = settings.url.replace( /\d+/, "" );
- assert.equal( url, baseURL + "name.html?abc&devo=hat&_=#brownies", "Make sure that the URL has its hash." );
+ // Clear the cache-buster param value
+ var url = settings.url.replace( /_=[^&#]+/, "_=" );
+ assert.equal( url, baseURL + "name.html?abc&devo=hat&_=#brownies",
+ "hash preserved for cache-busting request with query component and data." );
return false;
},
error: true
@@ -1133,7 +1137,7 @@ QUnit.module( "ajax", {
setup: function() {
Globals.register( "testBar" );
},
- url: window.location.href.replace( /[^\/]*$/, "" ) + baseURL + "mock.php?action=testbar",
+ url: url( "mock.php?action=testbar" ),
dataType: "script",
success: function() {
assert.strictEqual( window[ "testBar" ], "bar", "Script results returned (GET, no callback)" );
@@ -1146,7 +1150,7 @@ QUnit.module( "ajax", {
setup: function() {
Globals.register( "testBar" );
},
- url: window.location.href.replace( /[^\/]*$/, "" ) + baseURL + "mock.php?action=testbar",
+ url: url( "mock.php?action=testbar" ),
type: "POST",
dataType: "script",
success: function( data, status ) {
@@ -1161,7 +1165,7 @@ QUnit.module( "ajax", {
setup: function() {
Globals.register( "testBar" );
},
- url: window.location.href.replace( /[^\/]*$/, "" ).replace( /^.*?\/\//, "//" ) + baseURL + "mock.php?action=testbar",
+ url: url( "mock.php?action=testbar" ),
dataType: "script",
success: function() {
assert.strictEqual( window[ "testBar" ], "bar", "Script results returned (GET, no callback)" );
@@ -2303,7 +2307,22 @@ if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().re
} );
QUnit.asyncTest( "jQuery.getJSON( String, Function ) - JSON object with absolute url to local content", 2, function( assert ) {
- jQuery.getJSON( window.location.href.replace( /[^\/]*$/, "" ) + url( "mock.php?action=json" ), function( json ) {
+ var absoluteUrl = url( "mock.php?action=json" );
+
+ // Make a relative URL absolute relative to the document location
+ if ( !/^[a-z][a-z0-9+.-]*:/i.test( absoluteUrl ) ) {
+
+ // An absolute path replaces everything after the host
+ if ( absoluteUrl.charAt( 0 ) === "/" ) {
+ absoluteUrl = window.location.href.replace( /(:\/*[^/]*).*$/, "$1" ) + absoluteUrl;
+
+ // A relative path replaces the last slash-separated path segment
+ } else {
+ absoluteUrl = window.location.href.replace( /[^/]*$/, "" ) + absoluteUrl;
+ }
+ }
+
+ 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();