mardi 26 janvier 2016

Location Reload Jasmine

I got a problem with mocking the location reload functionality within Jasmine. I tried several methods (method 1 , method 2) to mock any location reload events but with no luck.

My situation is the following thing. I have a rather simple function:

function TestCall(xhr) {
   if (xhr === 401) {       
        location.reload();
   }
}

I tried creating the following Jasmine tests:

it("FakeCall", function (){
    spyOn(TestCall, 'reload').and.callFake(function(){});
    TestCall(401);
    expect(TestCall).toHaveBeenCalled(); // this should check if reload functionality have been called 
}); 

I want to mock the location reload function but I have no clue why this does not work. Can anyone guide/tell me what I do wrong?

Aucun commentaire:

Enregistrer un commentaire