unit testing - How to test getCookie function with Jasmine and PhantomJS -


i have function on window object so:

window.getcookie = function(name){    // cookie name, uses document.cookie this. }; 

now want test logic in unit tests i'm using jasmine , phantomjs. test looks like:

it('should cookie 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'); }); 

the thing turns out document.cookie '' when code executed within phantomjs. setting cookie on line 1 not doing anything. if log on line 2, value ''.

how around this?

mmm, it's strange document.cookie '' using phantomjs only. usually, when cookie has expired time no more available in document.cookie.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

IF statement in MySQL trigger -