TIL... How to test a window-redirect using Mocks
I was testing an action, which upon completion needed to redirect the user to a new page. Normally, in javascript you can redirect using :
1 | window.location = "newPath"; |
But that’s hard to test for. Thankfully there is a better way:
1 | window.location.assign("newPath"); |
You can then mock the assign function and test for that call! My thanks to the creators of jest for that insight!