Is it possible to mock [removed] in JavaScript?

后端 未结 6 522
猫巷女王i
猫巷女王i 2020-12-14 07:39

document.cookie is like a string, but it is not a string. To quote the example from the Mozilla doc:

document.cookie = \"name=oeschger\";
docume         


        
6条回答
  •  有刺的猬
    2020-12-14 08:18

    I figured out that jasmine has spyOnProperty which can be used for when you want to spy on getter and setters of objects. So I solved my issue with this:

    const cookie: string = 'my-cookie=cookievalue;';    
    spyOnProperty(document, 'cookie', 'get').and.returnValue(cookie);
    

提交回复
热议问题