我在窗口对象上有一个函数,如下所示:
window.getCookie = function(name){
// Get cookie with name, uses document.cookie for this.
};
现在,我想在我使用Jasmine和PhantomJS的单元测试中测试这个逻辑。测试看起来是这样的:
it('should get a cookie with a specific name.', function () {
// Setup
document.cookie = 'Foo=Bar; expires=Thu, 01 Jan 1970 00:00:00 UTC';
// Execute
var result = window.getCookie('Foo');
// Test
expect(result).toBe('Bar');
});
事实证明,当代码在PhantomJS中执行时,document.cookie始终为“”。因此,在第1行设置cookie基本上不会做任何事情。如果将其记录在第2行,则值为'‘。
我该如何解决这个问题呢?
发布于 2016-03-04 14:16:22
嗯,奇怪的是document.cookie只使用PhantomJ。通常,当cookie的时间过期时,它在document.cookie中不再可用。
https://stackoverflow.com/questions/30185877
复制相似问题