You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
this is bug report is mostly a PSA because you've already fixed it in the current dev branch, but maybe I'll save someone some time:
The validation added in tough-cookie@4.1.0, specifically the isObject function, fails in an environment that overrides the global toString method - for example, in a Jest test running in the jsdom environment.
What happens
Trying to create a new jar with new CookieJar() throws error [object Object].
Why
When you adapted the validator functions from check-types, you didn't bring over the locally defined toString function. That's fine in theory, the global object has a toString method, but it breaks if something redefines it - for example the jsdom environment, which replaces the default node global with a mocked window, where the toString method always returns undefined.
Temporary fix
Before creating the jar, define window.toString again:
window.toString=Object.prototype.toString;
The upcoming TS refactor should fix this - the new objectToString function uses uses Object.prototype.toString as expected) - but I'd be happy to submit a pull request. I mean. It's literally one line of code :D.
The text was updated successfully, but these errors were encountered:
Thanks for opening this issue and providing a temporary workaround for those who may be affected @corvidism ❤️
We'd gladly accept a PR fix for this. Most of our maintainer focus has been on preparing for the upcoming TS refactor so fixing this in 4.1.x is less of a priority at the moment.
Hi,
this is bug report is mostly a PSA because you've already fixed it in the current
dev
branch, but maybe I'll save someone some time:The validation added in
tough-cookie@4.1.0
, specifically theisObject
function, fails in an environment that overrides the globaltoString
method - for example, in a Jest test running in thejsdom
environment.What happens
Trying to create a new jar with
new CookieJar()
throws error[object Object]
.Why
When you adapted the validator functions from
check-types
, you didn't bring over the locally definedtoString
function. That's fine in theory, the global object has atoString
method, but it breaks if something redefines it - for example thejsdom
environment, which replaces the default node global with a mockedwindow
, where thetoString
method always returnsundefined
.Temporary fix
Before creating the jar, define
window.toString
again:The upcoming TS refactor should fix this - the new
objectToString
function uses usesObject.prototype.toString
as expected) - but I'd be happy to submit a pull request. I mean. It's literally one line of code :D.The text was updated successfully, but these errors were encountered: