From d29c877e8bdfd9406a1a4e142728b4621f7ace18 Mon Sep 17 00:00:00 2001 From: Matt Leon <108271225+wydengyre@users.noreply.github.com> Date: Sat, 27 Jan 2024 17:18:02 +0700 Subject: [PATCH] genres-test-cleanup (#30) genres tests cleanup --- lib/genres.test.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/genres.test.ts b/lib/genres.test.ts index fa6a952..7a291b8 100644 --- a/lib/genres.test.ts +++ b/lib/genres.test.ts @@ -5,18 +5,23 @@ import { NotFoundError } from "./error.js"; import { genresHtml } from "./genres.js"; import genresJson from "./test/generi.json" with { type: "json" }; -test("genresHtml", async () => { +test("genres", async (t) => { + await t.test(genresHtmlSuccess); + await t.test(genresHtmlNotFound); + await t.test(genresHtml500); +}); + +async function genresHtmlSuccess() { const fetchFn: typeof fetch = async (input) => { assert.strictEqual(input.toString(), "https://rai.dev/generi.json"); return json(genresJson); }; const conf = confWithFetch(fetchFn); - // just making sure this runs without error - const _html = await genresHtml(conf); -}); + await genresHtml(conf); +} -test("genresHtml 404", async () => { +async function genresHtmlNotFound() { const fetchFn: typeof fetch = async (input) => { assert.strictEqual(input.toString(), "https://rai.dev/generi.json"); return new Response("Not found", { status: 404 }); @@ -26,9 +31,9 @@ test("genresHtml 404", async () => { const expectedErr = new NotFoundError(new URL("https://rai.dev/generi.json")); const p = genresHtml(conf); await assert.rejects(p, expectedErr); -}); +} -test("genresHtml 500", async () => { +async function genresHtml500() { const fetchFn: typeof fetch = async (input) => { assert.strictEqual(input.toString(), "https://rai.dev/generi.json"); return new Response("Internal Server Error", { status: 500 }); @@ -40,7 +45,7 @@ test("genresHtml 500", async () => { ); const p = genresHtml(conf); await assert.rejects(p, expectedErr); -}); +} const confWithFetch = (fetchFn: typeof fetch) => ({ baseUrl: new URL("https://test.dev/"),