question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"ReferenceError: AbortSignal is not defined" during jest execution

See original GitHub issue

Bug 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:open
  • Created a year ago
  • Reactions:1
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
dios-davidcommented, Nov 4, 2022

fyi I updated to latest jest (29) and undici works fine with the node test environment

1reaction
feugycommented, Sep 16, 2022

I 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found