tests: update tests

This commit is contained in:
Tyler Wilding 2024-09-21 22:26:26 -04:00
parent cf51c1da50
commit ddc0a9643e
No known key found for this signature in database
GPG key ID: BF7B068C2FEFD7EF
2 changed files with 24 additions and 2 deletions

View file

@ -215,5 +215,7 @@ export async function initLocales(async: boolean) {
}); });
if (!async) { if (!async) {
await initPromise; await initPromise;
} else {
return initPromise;
} }
} }

View file

@ -1,12 +1,28 @@
import { afterEach, describe, expect, it, vi, type Mock } from "vitest"; import {
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
vi,
type Mock,
} from "vitest";
import { arch, platform } from "@tauri-apps/api/os"; import { arch, platform } from "@tauri-apps/api/os";
import { listOfficialReleases } from "./github"; import { listOfficialReleases } from "./github";
import { init } from "svelte-i18n";
import { initLocales } from "$lib/i18n/i18n";
vi.mock("@tauri-apps/api/os"); vi.mock("@tauri-apps/api/os");
global.fetch = vi.fn(); global.fetch = vi.fn();
function createFetchResponse(data: any) { function createFetchResponse(data: any) {
return { json: () => new Promise((resolve) => resolve(data)) }; return {
ok: true,
status: 200,
headers: new Map(),
json: () => new Promise((resolve) => resolve(data)),
};
} }
function createFakeGithubReleaseAsset(assetName) { function createFakeGithubReleaseAsset(assetName) {
@ -121,6 +137,10 @@ function createFakeGithubRelease(assetNames: string[]) {
}; };
} }
beforeAll(async () => {
await initLocales(true);
});
describe("listOfficialReleases", () => { describe("listOfficialReleases", () => {
afterEach(() => { afterEach(() => {
vi.clearAllMocks(); vi.clearAllMocks();