Browse Source

Improved way of testing jQuery's AJAX "script" and "jsonp" requests (#13554)

tags/2.0.12
Alexey Rogachev 8 years ago committed by Alexander Makarov
parent
commit
8e1a4208ed
  1. 27
      tests/js/tests/yii.test.js

27
tests/js/tests/yii.test.js

@ -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);
});
});
@ -1018,7 +1006,8 @@ describe('yii', function () {
});
after(function () {
ajaxDataType = 'script';
prefilterCallback = function () {
};
});
afterEach(function () {

Loading…
Cancel
Save