Skip to content

Commit

Permalink
Improved way of testing jQuery's AJAX "script" and "jsonp" requests (y…
Browse files Browse the repository at this point in the history
  • Loading branch information
arogachev authored and samdark committed Feb 13, 2017
1 parent 3575cc7 commit 8e1a420
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions tests/js/tests/yii.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -979,30 +979,18 @@ describe('yii', function () {

describe('asset filters', function () {
var server;
var ajaxDataType;
var prefilterCallback = function (options) {
options.crossDomain = false;
};
var jsResponse = {
status: 200,
headers: {'Content-Type': 'application/x-custom-javascript'},
headers: {'Content-Type': 'application/javascript'},
body: 'var foobar = 1;'
};

before(function () {
// Sent ajax requests with dataType "script" and "jsonp" are not captured by Sinon's fake server.
// As a workaround we can use custom dataType.
// This $.ajaxPrefilter handler must be run after the one from yii.js.
ajaxDataType = 'customscript';
$.ajaxPrefilter('script', function () {
return ajaxDataType;
});
$.ajaxSetup({
accepts: {
customscript: 'application/x-custom-javascript'
},
converters: {
'text customscript': function (result) {
return result;
}
}
$.ajaxPrefilter('script', function (options) {
prefilterCallback(options);
});
});

Expand All @@ -1018,7 +1006,8 @@ describe('yii', function () {
});

after(function () {
ajaxDataType = 'script';
prefilterCallback = function () {
};
});

afterEach(function () {
Expand Down

0 comments on commit 8e1a420

Please sign in to comment.