From 8e1a4208eddc4cce33d88dd1a09bdbc88a8c824a Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Tue, 14 Feb 2017 03:13:56 +0600 Subject: [PATCH] Improved way of testing jQuery's AJAX "script" and "jsonp" requests (#13554) --- tests/js/tests/yii.test.js | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/tests/js/tests/yii.test.js b/tests/js/tests/yii.test.js index ce0ce7c..fb51169 100644 --- a/tests/js/tests/yii.test.js +++ b/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 () {