Skip to content
Advertisement

Testing window.location in jest

I am trying to test the window functionality via jest. I have a function which appends a query param to the url and redirects the page to the other page. A rough snippet of the code is below:

JavaScript

I am new to jest and I am facing a bit of difficulty simulating the mock test for this, hence can you please help me with this. Thanks in advance.

Advertisement

Answer

I figured out a way to mock windows.location. I am attaching a code snippet which will be helpful for others who are trying to mock it.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement