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

Response.error() is not being treated as a response #652

Open
trajano opened this issue Dec 19, 2022 · 1 comment
Open

Response.error() is not being treated as a response #652

trajano opened this issue Dec 19, 2022 · 1 comment

Comments

@trajano
Copy link

trajano commented Dec 19, 2022

Here's a simple test that would demonstrate the problem.

import fetchMock from 'fetch-mock-jest';
it("should work with Response.error()", async () => {
    fetchMock.mock("https://trajano.net/bad-request", Response.error());
    const response = await fetch("https://trajano.net/bad-request");
    expect(response.status).toBe(0);
});
@trajano
Copy link
Author

trajano commented Dec 19, 2022

Workaround

  let fetchConfigResponse: (new () => Response) | undefined;

  beforeEach(() => {
    fetchConfigResponse = fetchMock.config.Response;
  })

  afterEach(() => {
    fetchMock.mockReset();
    fetchMock.config.Response = fetchConfigResponse;
  })

  it("Response.error type check", async () => {
    fetchMock.config.Response = Response;
    expect(Response.error() instanceof Response).toBe(true);
    expect(fetchMock.config.Response?.prototype.isPrototypeOf(Response.error())).toBe(true);
  });

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