Cookies.get() always returns empty when used with jsdom.
See original GitHub issueIn this block of code:
if (this.json) {
try {
cookie = JSON.parse(cookie);
} catch (e) {}
}
If this is undefined, it will throw an error causing a Cookies.get() to always return an empty {}.
The solution is to change the conditional to the following:
if (this && this.json) {
try {
cookie = JSON.parse(cookie);
} catch (e) {}
}
This is only failing in my test suite where jsdom is used instead of a browser. Everything seems to work in the browser.
Working on a PR.
Issue Analytics
- State:
- Created 7 years ago
- Comments:13 (9 by maintainers)
Top Results From Across the Web
Javascript document.cookie always returns empty string
Title: Javascript document.cookie always empty string . Answer: Can happen when there are only cookies with the HttpOnly flag set. No you can't ......
Read more >Document.cookie - Web APIs | MDN
The Document property cookie lets you read and write cookies associated with the document. It serves as a getter and setter for the...
Read more >jsdom-no-contextify | Yarn - Package Manager
A JavaScript implementation of the WHATWG DOM and HTML standards. This fork has no dependency on contextify. Be aware: the global scope of...
Read more >Changelog.md - jest-environment-jsdom-fourteen - GitLab
JSDOM.fragment() now creates fragments whose document has no ... isConnected to not always return false for nodes inside a shadow tree.
Read more >client/node_modules/jest-environment-jsdom-fourteen ...
Functions on the module you get from require('tough-cookie') . ... For use with .sort() , sorts a list of cookies into the recommended...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@dmatteo
I will take a look for v2.1.4.
Hey @FagnerMartinsBrack, I finally managed to get around this thread and try and reproduce whatever issue was here, without success though, or actually without failures…
I’ve created a small repo here https://github.com/dmatteo/jsCookieRepro that will also help clear out the
jsdomify.defaultcase. Good point on the fact that the CommonJS use case is not documented on the README, I will add that asap.There are 3 branches on the repo:
jsdomify 3.0.0which depends onjsdom 9.4.2import jsdomify from 'jsdomify'./node_modules/.bin/mocha --compilers js:babel-registerjsdomify 3.0.0which depends onjsdom 9.4.2var jsdomify = require('jsdomify').default.defaultpart is not ajsdomifyspecific thing, but it’s there because the library is exported as a default ES6 module and then transpiled via babel before publishing, so it can be used also via CommonJS./node_modules/.bin/mochajsdomify 2.1.0which depends onjsdom 8.2.0jsdomifythat was mentioned in the issue here../node_modules/.bin/mocha --compilers js:babel-registerAll the (2) tests in the 3 branches passes, so I’m not sure what was the issue here.
Does that help in any way?