Skip to content

Commit 3f6ba63

Browse files
committed
Fix #267 - incorrect handling of url argument
This fixes the issue when $.ajax() is called with an 'undefined' first argument and a url in the options object. Previously we were overriding the url with the undefined value versus the other way around.
1 parent 2c6ef1c commit 3f6ba63

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

dist/jquery.mockjax.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@
557557
} else {
558558
// work around to support 1.5 signature
559559
origSettings = origSettings || {};
560-
origSettings.url = url;
560+
origSettings.url = url || origSettings.url;
561561
}
562562

563563
// Extend the original settings for the request

dist/jquery.mockjax.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/jquery.mockjax.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@
546546
} else {
547547
// work around to support 1.5 signature
548548
origSettings = origSettings || {};
549-
origSettings.url = url;
549+
origSettings.url = url || origSettings.url;
550550
}
551551

552552
// Extend the original settings for the request

test/test-bugs.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,5 +405,25 @@
405405
}
406406
});
407407
});
408+
409+
t('Bug #267: handle undefined url in first arg', function(assert) {
410+
var done = assert.async();
411+
412+
$.mockjax({
413+
url: '/api/foo',
414+
contentType: 'application/json',
415+
responseText: { foo: 'bar' }
416+
});
417+
418+
$.ajax(undefined, {
419+
url: '/api/foo',
420+
dataType: 'json',
421+
error: qunit.noErrorCallbackExpected,
422+
success: function(data) {
423+
assert.deepEqual(data, { foo: 'bar' }, 'success gets correct data');
424+
},
425+
complete: done
426+
});
427+
});
408428

409429
})(window.QUnit, window.jQuery);

0 commit comments

Comments
 (0)