Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

releases.test.ts

38 lines1.2 KB

1import { afterEach, describe, expect, it, vi } from "vite-plus/test";
2​
3import { fetchLatestRelease } from "./releases";
4​
5afterEach(() => {
6 vi.unstubAllGlobals();
7});
8​
9describe("fetchLatestRelease", () => {
10 it("rejects a GitHub API error response instead of returning it as a release", async () => {
11 vi.stubGlobal("sessionStorage", { getItem: () => null });
12 vi.stubGlobal("fetch", async () =>
13 Response.json({ message: "API rate limit exceeded" }, { status: 403 }),
14 );
15​
16 await expect(fetchLatestRelease("stable")).rejects.toThrow("403");
17 });
18​
19 it("fetches release data when session storage access fails", async () => {
20 const release = {
21 tag_name: "v1.0.0",
22 html_url: "https://github.com/pingdotgg/t3code/releases/tag/v1.0.0",
23 published_at: "2026-01-01T00:00:00Z",
24 assets: [],
25 };
26 vi.stubGlobal("sessionStorage", {
27 getItem: () => {
28 throw new Error("Storage access denied");
29 },
30 setItem: () => {
31 throw new Error("Storage access denied");
32 },
33 });
34 vi.stubGlobal("fetch", async () => Response.json(release));
35​
36 await expect(fetchLatestRelease("stable")).resolves.toEqual(release);
37 });
38});