Last Updated: February 25, 2016
· artfulhacker

QUnit unit testing in js, window.location mocks

So recently I need to unit test some js code but this code used the variable, and in order to fully test the logic I had to mock the window.location global var.

In case anyone ever has to do something similar here is a snippet that works with QUnit:

test( "test initial mocks", function()
    custom_window =
            host: ""

        equal(, "", "we expect to be in the mock" );