From 55a40dcabd789290dffe9e9ed2320f426bda9e65 Mon Sep 17 00:00:00 2001 From: Zhihua Lai Date: Mon, 13 Oct 2025 10:25:07 +0100 Subject: [PATCH] Test setup and added a complex unit test --- tests/Functions.test.js | 22 ++++++++++++++++++++++ tests/test.setup.js | 10 ++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/tests/Functions.test.js b/tests/Functions.test.js index 71dbaaf..5104a5e 100755 --- a/tests/Functions.test.js +++ b/tests/Functions.test.js @@ -34,4 +34,26 @@ describe("convertMarkdownToHtml", () => { ); expect(() => convertMarkdownToHtml(123)).toThrow("Markdown parse error"); }); + + it("converts complex markdown with multiple elements", () => { + const md = ` +# Title + +This is a paragraph with **bold** text and a [link](https://example.com). + +- List item 1 +- List item 2 + +> A blockquote +`; + const html = convertMarkdownToHtml(md); + expect(html).toContain("

Title

"); + expect(html).toContain( + '

This is a paragraph with bold text and a link.

', + ); + expect(html).toContain( + "", + ); + expect(html).toContain("
\n

A blockquote

\n
"); + }); }); diff --git a/tests/test.setup.js b/tests/test.setup.js index 47c7ab4..fc9908c 100644 --- a/tests/test.setup.js +++ b/tests/test.setup.js @@ -1,2 +1,8 @@ -import { randomUUID } from "node:crypto"; // Node.js built-in crypto -global.crypto = { randomUUID }; // Mock or polyfill necessary crypto functions +import { randomUUID } from "node:crypto"; + +if (!globalThis.crypto?.randomUUID) { + Object.defineProperty(globalThis, "crypto", { + value: { randomUUID }, + configurable: true, + }); +}