Skip to content

Please support all acceptable types for the Response constructor #218

@andreasg123

Description

@andreasg123

In addition to string, the Response constructor supports several other types. That is important for mocking an arrayBuffer response.

Unfortunately, the typing for MockResponseInitFunction only supports string. The following works but requires an ugly cast:

const buffer = new Float32Array(10).buffer;
fetchMock.mockResponse(req => Promise.resolve({ body: buffer as unknown as string }));

As a bonus, it would be nice if these other types could be checked in addition to string to allow for the shorter form that doesn't require an object with a body property.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions