1

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

Deepak
  • 353
  • 5
  • 14
  • Can you show us your test, and what you've tried so far (that doesn't work)? You should be able to create a `setup` method on your `module` and mock out the `document.referrer` property, so maybe there is an issue with how you've done it. – Jordan Kasper Jan 06 '15 at 19:08

0 Answers0