Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
How to mock the entire AbortController class using jest

I'm using Jest and AbortController at the same time. AbortController has a signal property which returns an AbortSignal, which itself has a reason property. However, the reason property isn't supported in node yet, thus all of my test are failing due to this.

I've tried

jest.spyOn(AbortController.prototype, 'AbortController').mockImplementation(...)

to mock the constructor but I still got the following error :

"Argument of type '"AbortController"' is not assignable to parameter of type '"abort"'."

I cannot use jest.mock() because AbortController isn't imported.

I don't really know what to do from now on, has anyone ever tried this ?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

I solved this problem by adding these lines to my jest configuration, inside the package.json :

"jest": {
        [...yourConfig],
        "globals": {
            "ts-jest": {
                "isolatedModules": true
            }
        },
}

The tests weren't compiling because of a typing problem. Jest was using @types/node. This solved the problem.

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!