diff --git a/lib/sinon/util/fake_server.js b/lib/sinon/util/fake_server.js index 1278d87bf..54037586e 100644 --- a/lib/sinon/util/fake_server.js +++ b/lib/sinon/util/fake_server.js @@ -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();