Skip to content

Commit

Permalink
test: add fetchData test
Browse files Browse the repository at this point in the history
  • Loading branch information
velut committed Apr 20, 2024
1 parent 4e4bef8 commit fbc1eb1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/fetch-data.test.ts
Original file line number Diff line number Diff line change
@@ -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",
}
`);
});

0 comments on commit fbc1eb1

Please sign in to comment.