Skip to content

Commit

Permalink
Add support for React Native window location format Fixes sinonjs#1362
Browse files Browse the repository at this point in the history
  • Loading branch information
greena13 authored and lucasfcosta committed May 16, 2017
1 parent 38e3ec4 commit 8cade48
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion lib/sinon/util/fake_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,32 @@ function responseArray(handler) {
return response;
}

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

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

function getWindowLocation() {
if ( typeof window !== "undefined") {
if (typeof window.location !== 'undefined') {
// Browsers place location on window
return window.location;
} else if((typeof window.window !== 'undefined') && (typeof window.window.location !== 'undefined')) {
// React Native on Android places location on window.window
return window.window.location;
} else {
return getDefaultWindowLocation();
}
} else {
// Fallback
return getDefaultWindowLocation();
}
}

function getDefaultWindowLocation() {
return { "host": "localhost", "protocol": "http"}
}


function matchOne(response, reqMethod, reqUrl) {
var rmeth = response.method;
var matchMethod = !rmeth || rmeth.toLowerCase() === reqMethod.toLowerCase();
Expand Down

0 comments on commit 8cade48

Please sign in to comment.