jefflau / jest-fetch-mock

Jest mock for fetch
MIT License
881 stars 116 forks source link

expose normalizeResponse #246

Open sibelius opened 1 year ago

sibelius commented 1 year ago

I'd like to build something like this

export const assertFetch = (url, options, fn: MockResponseInitFunction) => {
  fetchMock.mockResponseOnce(async (req) => {
    expect(req.url).toBe(url);
    expect(req.options).toEqual(options);

    return normalizeResponse(fn);
  });
};

Where I assert the value of url and option of the request, but also mock the response

for this, I need to reuse normalizeResponse to keep the same api