Last active
May 10, 2019 18:01
-
-
Save Eightyplus/765c22e81801ca58a2fd0cea35237732 to your computer and use it in GitHub Desktop.
Mock window.location in jest
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
describe('test reading window.location', () => { | |
beforeEach(() => | |
window.history.replaceState( | |
{}, | |
'Title', | |
'/?code=0123456789&other=yes' | |
) | |
); | |
it('should have code', () => { | |
expect(window.location.search).toEqual(expect.stringContaining('code=')); | |
}); | |
it('should read code', () => { | |
expect(window.location.search.replace(/.*code=([0-9]*).*/, '$1')).toBe('0123456789'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment