Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for AbortSignal.timeout() TimeoutError #242

Open
Radi-Mortada opened this issue Dec 29, 2022 · 0 comments
Open

Add support for AbortSignal.timeout() TimeoutError #242

Radi-Mortada opened this issue Dec 29, 2022 · 0 comments

Comments

@Radi-Mortada
Copy link

Currently the abort signal error is forced to be as following:
https://github.com/jefflau/jest-fetch-mock/blob/master/src/index.js#L88 source code:

const abortError = () =>
  new DOMException('The operation was aborted. ', 'AbortError')

My test mock:

  const abortSignalTimeout = jest.spyOn(AbortSignal, 'timeout');

  beforeAll(() => {
    fetchMock.mockResponseOnce(() => {
      const promise = new Promise((resolve) => {
        setTimeout(() => {
          resolve('resolved after timeout of `5`');
        }, 5);
      });

      return promise;
    });

    const signal = AbortSignal.timeout(1);

    abortSignalTimeout.mockReturnValue(signal);
  });

there is no way to obtain the correct abort error TimeoutError instead of AbortError
https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout

@Radi-Mortada Radi-Mortada changed the title Add support for AbortSignal.timeout() TimeoutError Add support for AbortSignal.timeout() TimeoutError Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant