Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReactNative compatibility. Allow sinon fakeServer to run in React Native #1052

Merged
merged 7 commits into from
Jun 4, 2016
2 changes: 1 addition & 1 deletion lib/sinon/util/fake_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function responseArray(handler) {
return response;
}

var wloc = typeof window !== "undefined" ? window.location : {};
var wloc = typeof window !== "undefined" ? window.location : { "host": "localhost", "protocol": "http"};
var rCurrLoc = new RegExp("^" + wloc.protocol + "//" + wloc.host);

function matchOne(response, reqMethod, reqUrl) {
Expand Down
4 changes: 3 additions & 1 deletion lib/sinon/util/fake_xml_http_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ var supportsBlob = (function () {
return false;
}
})();
var isReactNative = global.navigator && global.navigator.product === "ReactNative";
var sinonXhr = { XMLHttpRequest: global.XMLHttpRequest };
sinonXhr.GlobalXMLHttpRequest = global.XMLHttpRequest;
sinonXhr.GlobalActiveXObject = global.ActiveXObject;
sinonXhr.supportsActiveX = typeof sinonXhr.GlobalActiveXObject !== "undefined";
sinonXhr.supportsXHR = typeof sinonXhr.GlobalXMLHttpRequest !== "undefined";
sinonXhr.workingXHR = getWorkingXHR(global);
sinonXhr.supportsCORS = sinonXhr.supportsXHR && "withCredentials" in (new sinonXhr.GlobalXMLHttpRequest());
sinonXhr.supportsCORS = isReactNative ||
(sinonXhr.supportsXHR && "withCredentials" in (new sinonXhr.GlobalXMLHttpRequest()));

var unsafeHeaders = {
"Accept-Charset": true,
Expand Down