-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
instanceof Error
check returns unexpected result
#3082
Comments
Can you provide a reproduction that doesn't use Jest? We cannot help debug Jest usage. |
@domenic Sure! I just updated my repo. The code is this const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const dom = new JSDOM(`<body>
<script>
try {
// invalid URL to be thrown
const url = new URL("something");
} catch (e) {
console.log(e instanceof Error); // expect true
}
</script>
</body>`, { runScripts: "dangerously" });
// `node index.js` prints `false` |
Thanks. I guess then this is "Errors and other globals from the outer Node.js environment are still used" from #2727, which is pretty hard to fix. |
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Basic info:
Minimal reproduction case
I'm using JSDom via Jest, this is my repo repro
https://github.com/akphi/jest-jsdom-test/blob/main/src/basic.test.js for Jest
https://github.com/akphi/jest-jsdom-test/blob/main/index.js for native JSDOM example
How does similar code behave in browsers?
It behaves as expected in the browser: i.e.
instanceof Error
returnstrue
Link: https://codesandbox.io/s/xenodochial-gauss-2cqjx?file=/src/App.tsx
Points to consider
The gist of the problem is by providing an invalid base URL, the package
whatwg-url
used byjsdom
throws aTypeError
which gets picked up by my test, but fails myinstanceof Error
check.I did a little bit of digging, there are many issues raised regarding sandboxing or
instanceof
check, though I don't understand fully, I see 2 categories:Jest
with default settings so I hope I did not misconfigured anything hereError
is somehow different than theError
in myinstanceof
check.The text was updated successfully, but these errors were encountered: