Created
June 21, 2019 05:05
-
-
Save jericbas/11cbce3a1481b00492a42e416d92752a to your computer and use it in GitHub Desktop.
Mock `window.location.search`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('mocks search', () => { | |
delete window.location; | |
window.location = { search: '?query=phone' }; | |
expect(window.location.search).toEqual('?query=phone'); | |
}); |
Thanks. Not that easy to make it work with typescript 😅
Mock window.location.search
in TypeScript:
global.window = Object.create(window);
Object.defineProperty(window, 'location', {
value: {
search: '?query=phone',
},
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks chatGPT? 😂🤣