URL behaves differently when run with jest
See original GitHub issue🐛 Bug Report
The object thrown by the constructor of URL
is not an instance of Error
.
To Reproduce
Create a file error.test.js
with the following contents:
#!/usr/bin/env node
try {
new URL("not_a_url");
} catch (anything) {
process.exit(anything instanceof Error ? 0 : 1);
}
If you run node error.test.js
the program exits successfully. However, if you use jest to run this file you get:
§ jest
● process.exit called with "1"
3 | new URL("not_a_url");
4 | } catch (anything) {
> 5 | process.exit(anything instanceof Error ? 0 : 1);
| ^
6 | }
7 |
at Object.exit (error.test.js:5:11)
RUNS ./error.test.js
Expected behavior
I expect the error raised by the call to URL
to be an instance of Error
.
envinfo
System:
OS: macOS Mojave 10.14.6
CPU: (8) x64 Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
Binaries:
Node: 12.1.0 - /usr/local/bin/node
Yarn: 1.22.0 - ~/.yarn/bin/yarn
npm: 6.13.7 - /usr/local/bin/npm
Issue Analytics
- State:
- Created 3 years ago
- Comments:17
Top Results From Across the Web
Different behavior from Jest test when run locally and run via ...
Depends on your project. Since JSDOM behaves differently in, a reasonable explanation would be that test runs are performed with different Jest ......
Read more >Globals - Jest
Runs a function after all the tests in this file have completed. If the function returns a promise or is a generator, Jest...
Read more >Introduction to Nuxt Test Utils - Reflect.run
Here we provide an overview of Nuxt Test Utils, its features, and how to set up a test environment with `nuxt/test-utils`.
Read more >How To Write Snapshot Tests For React Components With Jest
Snapshot testing allows you to ensure your output continues to behave as expected. This is useful because as you revisit your code to...
Read more >Testing React Applications with Jest - Auth0
Jest run tests in parallel processes thus minimizing test runtime. ... This however is not an indicator that the component behaves as it ......
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 FreeTop 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
Top GitHub Comments
@lukasoppermann Something like
const URLSearchParams = require('url').URLSearchParams
, if you look atrequire('url')
is actually this:This is #2549, yeah
Yeah, this behavior is specific to Jest since we use the
vm
module to create sandboxes -mocha
runs all the tests in the same context.Latest update to #2549 is essentially https://github.com/nodejs/node/issues/31852