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

322
Views
Catch call to new AbortController()

I have this piece of code:

if (this.isRequestPending) {
  this.conversationsAbortController.abort()
  this.conversationsAbortController = new AbortController()
}

I'm already able to catch the call to .abort() using jest.spyOn(AbortController.prototype, 'abort') but I'd like to also catch the new AbortController().

I've tried:

  • jest.spyOn(AbortController.prototype, 'new')
  • jest.spyOn(AbortController.prototype, 'constructor')
  • jest.spyOn(AbortController.prototype, 'AbortController')

But it doesn't seem to work.

I did look at the global.d.ts file for this:

interface AbortController {
  /**
   * Returns the AbortSignal object associated with this object.
   */

  readonly signal: AbortSignal;
  /**
   * Invoking this method will set this object's AbortSignal's aborted flag and signal to any observers that the associated activity is to be aborted.
   */
  abort(): void;
}

/** A signal object that allows you to communicate with a DOM request (such as a Fetch) and abort it if required via an AbortController object. */
interface AbortSignal {
  /**
   * Returns true if this AbortSignal's AbortController has signaled to abort, and false otherwise.
   */
  readonly aborted: boolean;
}

declare var AbortController: {
  prototype: AbortController;
  new(): AbortController;
};

declare var AbortSignal: {
  prototype: AbortSignal;
  new(): AbortSignal;
  // TODO: Add abort() static
};

But I'm not sure what to make of it.

about 4 years ago · Juan Pablo Isaza
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!