Tengo este fragmento de código:
if (this.isRequestPending) { this.conversationsAbortController.abort() this.conversationsAbortController = new AbortController() } Ya puedo captar la llamada a .abort() usando jest.spyOn(AbortController.prototype, 'abort') pero también me gustaría captar el new AbortController() .
He intentado:
jest.spyOn(AbortController.prototype, 'new')jest.spyOn(AbortController.prototype, 'constructor')jest.spyOn(AbortController.prototype, 'AbortController')Pero no parece funcionar.
Miré el archivo global.d.ts para esto:
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 };Pero no estoy seguro de qué hacer con eso.