When you run unit tests (I am using Jestjs) on functions which read window.location.href or window.location.search, you need to somehow mock the value. Problem is that when you try to edit the value of window.location.search it will not work. Neither will work overriding it by Object.defineProperty(). But there is a simple workaround solution, and that …