Skip to content

Commit

Permalink
Merge pull request #1363 from greena13/master
Browse files Browse the repository at this point in the history
Add support for React Native window location format Fixes sinonjs/sin…
  • Loading branch information
fatso83 committed Apr 24, 2017
2 parents 38e3ec4 + 4fe0a73 commit 0127365
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion lib/sinon/util/fake_server.js
Expand Up @@ -21,7 +21,31 @@ function responseArray(handler) {
return response;
}

var wloc = typeof window !== "undefined" ? window.location : { "host": "localhost", "protocol": "http"};
function getDefaultWindowLocation() {
return { "host": "localhost", "protocol": "http" };
}

function getWindowLocation() {
if (typeof window === "undefined") {
// Fallback
return getDefaultWindowLocation();
}

if (typeof window.location !== "undefined") {
// Browsers place location on window
return window.location;
}

if ((typeof window.window !== "undefined") && (typeof window.window.location !== "undefined")) {
// React Native on Android places location on window.window
return window.window.location;
}

return getDefaultWindowLocation();
}

var wloc = getWindowLocation();

var rCurrLoc = new RegExp("^" + wloc.protocol + "//" + wloc.host);

function matchOne(response, reqMethod, reqUrl) {
Expand Down

0 comments on commit 0127365

Please sign in to comment.