I have a function like this which I would like to write a unit test for :
function A () {
var x = document.referrer;
//Do something with 'a'
}
I would like to write a unit test, to test this function. I'm using QUnit with sinon.js for stubs and mocks. Is there a way for me to mock the document object so that I can provide a value for the referrer and test my logic? I tried assigning a value to document.referrer
in my setup
function, but that didn't work
Update
This is the test which I'm trying :
module("Verify Referrer", {
setup : function () {
this.documentMock = sinon.mock(document);
this.documentMock.referrer = "http://www.test.com";
},
teardown : function () {
this.documentMock.restore();
}
});
test("UrlFilter test url in white list", function() {
equal(document.referrer, "http://www.test.com");
});
I also tried using stub