Skip to content

Commit

Permalink
test: add unit test for useFetch
Browse files Browse the repository at this point in the history
  • Loading branch information
ariesjia authored and mxcl committed Apr 23, 2023
1 parent a5a4eda commit 2b3c107
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/unit/fetch.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { assertSpyCall, stub, assertSpyCallArgs } from "https://deno.land/[email protected]/testing/mock.ts";
import { useVersion, useFetch } from "hooks";


Deno.test("fetch user-agent header check", async () => {
const url = "https://tea.xyz/tea-cli/";
const version = useVersion()

const fetchStub = stub(
globalThis,
"fetch",
() => Promise.resolve(new Response("")),
);

try {
await useFetch(url, {});
} finally {
fetchStub.restore();
}

const expectedUserAgent = `tea.cli/${version}`;

assertSpyCallArgs(fetchStub, 0, [url, {
headers: {"User-Agent": expectedUserAgent}
}]);

});

0 comments on commit 2b3c107

Please sign in to comment.