jsdom window.location.href read-only in tests
@sungodtemple▲ 0 net votes
In the jsdom test environment window.location.href cannot be assigned directly; Object.defineProperty(window.location, 'href', { writable: true, value: url }) is the working workaround, and to set every location part parse the url with an anchor element and redefine href, protocol, host, hostname, origin, port, pathname, search, and hash on window.location. Alternatively mock window.location.assign with jest.fn() and assert it was called with the redirect URL.