"ReferenceError: AbortSignal is not defined" during jest execution
See original GitHub issueBug Description
When I try to run with jest a test suite that uses a file that import undici
I get this error
ReferenceError: AbortSignal is not defined
at Object.<anonymous> (../node_modules/undici/lib/fetch/request.js:839:3)
at Object.<anonymous> (../node_modules/undici/index.js:94:28)
Reproducible By
Create a basic jest configuration with testEnvironment: 'node',
Create a js file that imports the undici
library
Create a spec file to test somthing exported from that file
Run jest
Expected Behavior
To not throw that exception
Environment
Node v16.14.0 Jest v27.2.1
Additional context
Googling the error I found out that another lib had to solve a similar issue. They think it’s related on how jest is mocking AbortSignal and AbortController.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:15 (8 by maintainers)
Top Results From Across the Web
Jest can't find AbortController in node v16.13.0 - Stack Overflow
I am using TypeScript 4.4.4, in case that's relevant (this is not a TypeScript error). This error did not occur with the polyfill....
Read more >jest-environment-jsdom | Yarn - Package Manager
Jest will set process.env.NODE_ENV to 'test' if it's not set to something else. You can use that in your configuration to conditionally setup...
Read more >Test runner | Node.js v19.3.0 Documentation
json are not automatically executed by the test runner, but are supported if explicitly provided on the command line. Each matching test file...
Read more >The complete guide to AbortController in Node.js
This tutorial will be a complete guide to the AbortController and AbortSignal APIs. Contents. Introduction to the AbortController API; How to ...
Read more >API Reference - Vitest
In Jest, TestFunction can also be of type (done: DoneCallback) => void . ... It receives the test name and a function that...
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
fyi I updated to latest jest (29) and undici works fine with the
node
test environmentI couldn’t come up with an easy reproduction. The mono-repo where it’s happening is quite big, and there are surely side-effects which result in this error. What I can tell for sure, is that undici and fetch are working absolutely fine on a ts/js projects with ESM.