TIL... How to test a window-redirect using Mocks

2018-06-26 This post is over 2 years old

I was testing an action, which upon completion needed to redirect the user to a new page. Normally, in javascript you can redirect using :

window.location = "newPath";

But that's hard to test for. Thankfully there is a better way:


You can then mock the assign function and test for that call! My thanks to the creators of jest for that insight!