-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
URL behaves differently when run with jest #10045
Comments
Is jest perhaps not using the same implementation of |
Indeed printing out |
@fredefox looks like you are correct, Instead, it is related to #2549 (via #6788 (comment)). |
This does look like it could be a duplicate. Yes. Thanks @carsonreinke. What I'm not really getting is what it has to do with |
@fredefox it is really strange, I have not really gotten to the bottom of it, but I did try using https://www.npmjs.com/package/jest-runner-mocha and it does NOT exhibit that behavior. |
I am getting |
I don't think that's related, no. |
This is #2549, yeah
Yeah, this behavior is specific to Jest since we use the Latest update to #2549 is essentially nodejs/node#31852 |
Thanks @SimenB |
@fredefox I believe a good work around for this problem, wherever you are using |
I wasn't aware that I could import built-ins. Would you happen to know how you would modify my example to circumvent this? If you don't know off the top of your head it's ok. |
@fredefox so I think as simple as adding Here is an example: const URL = require('url');
try {
new URL("not_a_url");
}
catch (anything) {
console.log(anything instanceof TypeError); //will be true
}
try {
new global.URL("not_a_url");
}
catch (anything) {
console.log(anything instanceof TypeError); //will be false
} I'm not really sure how this would impact the polyfill though, probably nothing since this is a Node/Jest only problem. |
However, when I tried it I found that the resulting object is actually not the same, as there is not |
@lukasoppermann Something like {
Url: [Function: Url],
parse: [Function: urlParse],
resolve: [Function: urlResolve],
resolveObject: [Function: urlResolveObject],
format: [Function: urlFormat],
URL: [Function: URL],
URLSearchParams: [Function: URLSearchParams],
domainToASCII: [Function: domainToASCII],
domainToUnicode: [Function: domainToUnicode],
pathToFileURL: [Function: pathToFileURL],
fileURLToPath: [Function: fileURLToPath]
} |
Ah. Thank you very much @carsonreinke! That'll do it. |
And re the "not the same" part. Just to expand on what @carsonreinke already wrote. In his example he's shadowing the built-in URL, but the thing doing the shadowing, is not the same as the thing it is shadowing. The thing he is shadowing is present at |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🐛 Bug Report
The object thrown by the constructor of
URL
is not an instance ofError
.To Reproduce
Create a file
error.test.js
with the following contents:If you run
node error.test.js
the program exits successfully. However, if you use jest to run this file you get:Expected behavior
I expect the error raised by the call to
URL
to be an instance ofError
.envinfo
The text was updated successfully, but these errors were encountered: