Skip to content

Commit 3809061

Browse files
committed
ajax test: use makeMap
1 parent d61b3a4 commit 3809061

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

ajax-test.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var ajax = require('can-util/dom/ajax/ajax');
22
var namespace = require("can-namespace");
3+
var makeMap = require('can-util/js/make-map/make-map');
34

45
QUnit = require('steal-qunit');
56

@@ -23,10 +24,11 @@ var makeFixture = function(XHR){
2324
};
2425
};
2526

26-
// A helper to make a predicate for a given array that checks whether it contains a given value:
27-
var makePredicateContains = function (arr){
27+
// A helper to make a predicate for a given comma-separated list that checks whether it contains a given value:
28+
var makePredicateContains = function (str){
29+
var obj = makeMap(str);
2830
return function(val){
29-
return arr.indexOf(val) !== -1;
31+
return obj[val];
3032
};
3133
};
3234

@@ -121,12 +123,9 @@ if(typeof XDomainRequest === 'undefined') {
121123

122124
// CORS simple requests: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Simple_requests
123125
var isSimpleRequest = true, restore;
124-
var isSimpleMethod = makePredicateContains(['GET', 'POST', 'HEAD']);
125-
var isSimpleHeader = makePredicateContains([
126-
'Accept', 'Accept-Language', 'Content-Language', 'Content-Type',
127-
'DPR', 'Downlink', 'Save-Data', 'Viewport-Width', 'Width'
128-
]);
129-
var isSimpleContentType = makePredicateContains(['application/x-www-form-urlencoded', 'multipart/form-data', 'text/plain']);
126+
var isSimpleMethod = makePredicateContains("GET,POST,HEAD");
127+
var isSimpleHeader = makePredicateContains("Accept,Accept-Language,Content-Language,Content-Type,DPR,Downlink,Save-Data,Viewport-Width,Width");
128+
var isSimpleContentType = makePredicateContains("application/x-www-form-urlencoded,multipart/form-data,text/plain");
130129

131130
restore = makeFixture(function () {
132131
this.open = function (type, url) {

0 commit comments

Comments
 (0)