Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

323
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda