diff --git a/tests/e2e/.gitkeep b/tests/e2e/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/integration/.gitkeep b/tests/integration/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/unit/example_test.ts b/tests/unit/example_test.ts new file mode 100644 index 0000000..1de45e0 --- /dev/null +++ b/tests/unit/example_test.ts @@ -0,0 +1,61 @@ +import { assertEquals, assertExists } from "@std/assert"; +import { mockFetch, restoreFetch } from "../helpers/api_mock.ts"; +import { notes, students } from "../helpers/fixtures.ts"; +import { cleanupDOM, setupDOM } from "../helpers/render.ts"; + +Deno.test("fixtures - students have expected shape", () => { + assertEquals(students.length, 3); + assertEquals(students[0].nom, "Dupont"); + assertExists(students[0].numEtud); +}); + +Deno.test("mockFetch - returns mocked data for matching route", async () => { + mockFetch({ + "/students": students, + "/notes": notes, + }); + + try { + const res = await fetch("http://localhost/api/students"); + assertEquals(res.status, 200); + + const data = await res.json(); + assertEquals(data.length, 3); + assertEquals(data[0].nom, "Dupont"); + } finally { + restoreFetch(); + } +}); + +Deno.test("mockFetch - returns 404 for unknown routes", async () => { + mockFetch({}); + + try { + const res = await fetch("http://localhost/api/unknown"); + assertEquals(res.status, 404); + } finally { + restoreFetch(); + } +}); + +Deno.test({ + name: "happy-dom - document is available after setup", + sanitizeResources: false, + sanitizeOps: false, + fn() { + setupDOM(); + + try { + const doc = globalThis.document; + assertExists(doc); + + const div = doc.createElement("div"); + div.textContent = "hello"; + doc.body.appendChild(div); + + assertEquals(doc.body.textContent, "hello"); + } finally { + cleanupDOM(); + } + }, +});