View Full Version : Mocking web request in Javascript

07-03-2012, 03:17 PM
I am working on writing a Qunit test for my javascript function. My function has a if statement like this:
if(window.location.pathname.toLowerCase() == "/search/home.html" )
Everything I do is inside this if statement. I need to find a way how I can mock the window.location.pathname from my test case. I would highly appreciate your suggestions.

07-04-2012, 12:19 AM
Simply set up the script so that it runs from a file called home.html in a folder called search in the root directory of your hard drive. That way you don't have to mock the path as it will actually be that.

Alternatively install a web server such as WAMP or XAMPP onto your computer and then you can put the search folder inside whatever folder you tell the web server is the root directory.

If you are just after a quick way to test the code inside the if statement then comment out the if statement so the code always runs.