I'm new to Jasmine unit testing. I have written a function something like below.
//retrieve hash value from the url
var hash = window.location.hash;
//if hash exists, create a url and redirect
if(hash != undefined && hash.length > 0){
var newHref = hash.replace(/^#hash=/, '');
window.location = newHref;
}
Basically, it reads the value from window hash and replaces the value and reloads with the new href. In Jasmine have written a test something like below.
describe("onHashChange()", function() {
var href = "http://example.com/contactUs?abc=name";
var windowHash = "#hash="+href;
var newHref = windowHash.replace(/^#hash=/, '');
it('passes if Urls are equal', function() {
expect(href).toEqual(newHref);
});
});
Is this the right test and how do I mock window.location.href in jasmine.