diff --git a/src/fetch-data.test.ts b/src/fetch-data.test.ts new file mode 100644 index 0000000..56bba41 --- /dev/null +++ b/src/fetch-data.test.ts @@ -0,0 +1,17 @@ +import { expect, test, vi } from "vitest"; +import { z } from "zod"; +import { fetchData } from "./fetch-data"; + +const fetch = vi.fn(); + +vi.stubGlobal("fetch", fetch); + +test("fetchData", async () => { + fetch.mockResolvedValueOnce({ json: () => ({ foo: "bar" }) }); + expect(await fetchData(z.object({ foo: z.string() }), "https://example.com")) + .toMatchInlineSnapshot(` + { + "foo": "bar", + } + `); +});