From 4fe0a7372a7b7f583c5790ac8bb5ee349f6d7e89 Mon Sep 17 00:00:00 2001 From: Aleck Greenham Date: Sat, 22 Apr 2017 08:13:17 +0100 Subject: [PATCH] Flatten structure of getWindowLocation() --- lib/sinon/util/fake_server.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/sinon/util/fake_server.js b/lib/sinon/util/fake_server.js index af6292a71..76b9d3fad 100644 --- a/lib/sinon/util/fake_server.js +++ b/lib/sinon/util/fake_server.js @@ -26,19 +26,21 @@ function getDefaultWindowLocation() { } 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; - } - + if (typeof window === "undefined") { + // Fallback return getDefaultWindowLocation(); } - // Fallback + 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(); }