DRFR0ST / bun-bagel

🥯 The Bun fetch mocker with a hole lot of flavor.
MIT License
18 stars 5 forks source link

Ability for 2nd arg to be a Response, Promise, or function that returns these or existing 2nd args #19

Open gadicc opened 1 month ago

gadicc commented 1 month ago

Super handy, used in the popular fetch-mock (doc link) package too.

Maybe this should be 3 issues :sweat_smile: But here are some examples

// Func that return options
mock("*", () => ({ data: { name: "Foo" } });
mock("*", async () => ({ data: { name: "Foo" } });

// Responses
mock("*", new Response({ status: 200, statusText: "ok" });
mock("*", async () => new Response({ status: 200, statusText: "ok" });

Obviously these examples are somewhat simplified and not so impressive as is, however, they really open the door for some fun stuff. e.g. I'm currently working on the next major version of fetch-mock-cache. Just finished the pure bun code and would be awesome to have a bun-bagel example too.

Thanks for this awesome project and choosing to make it public! :pray: