Skip to content

Commit

Permalink
feat: allow more types of overloads of mockResponse (#26)
Browse files Browse the repository at this point in the history
This PR makes it possible to use more types of overloaded functions:

```ts
fetch.mockResponseOnce('x');
fetch.mockResponseOnce({ body: 'x' }); // previously not allowed
fetch.mockResponseOnce(new Response('x'));  // previously not allowed

fetch.mockResponseOnce(() => 'x');
fetch.mockResponseOnce(() => ({ body: 'x' }));
fetch.mockResponseOnce(() => new Response('x'));

fetch.mockResponseOnce(() => Promise.resolve('x'));
fetch.mockResponseOnce(() => Promise.resolve({ body: 'x' }));
fetch.mockResponseOnce(() => Promise.resolve(new Response('x')));
```

This could make certain cases less awkward, like
#25 (comment):
```ts
fetch.mockResponseOnce({ status: 204 });
fetch.mockResponseOnce(new Response(null, { status: 204 }));
```
  • Loading branch information
dirkluijk authored Oct 28, 2024
1 parent 17f9f68 commit 46bbb06
Show file tree
Hide file tree
Showing 4 changed files with 1,176 additions and 463 deletions.
Loading

0 comments on commit 46bbb06

Please sign in to comment.