4

I am using Jasmine for unit testing, and document.cookie in my code. Is it possible to mock document.cookie in my test file ?

I found out that I could use this :

var mock = {
    value_: '', 

    get cookie() {
        return this.value_;
    },

    set cookie(value) {
        this.value_ += value + ';';
    }
};

But I don't know how to tell Javascript that I want to use this instead of the document.cookie ? Is it possible ?

c5656
  • 41
  • 2
  • Did you check http://stackoverflow.com/questions/10142020/safely-overriding-document-cookie-in-google-chrome-extension ? – Dash Apr 21 '17 at 14:06

0 Answers0