From 78780bb183db645fac1b940e811b32aefb564d8c Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Thu, 13 Nov 2025 13:33:19 -0800 Subject: [PATCH] Refactor: Improve markdown test robustness with DOM parsing --- tests/5_markdown_parser/test.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/5_markdown_parser/test.js b/tests/5_markdown_parser/test.js index 22860c4..e4d0266 100644 --- a/tests/5_markdown_parser/test.js +++ b/tests/5_markdown_parser/test.js @@ -6,14 +6,13 @@ export default { // - The function should handle: headers (h1-h6), bold, italic, links, code blocks, inline code, lists (ordered/unordered), and blockquotes. // - Return the resulting HTML string.`, runTest: async (parseMarkdown) => { - const assert = { - strictEqual: (a, e, m) => { if (a !== e) throw new Error(m || `FAIL: ${a} !== ${e}`) }, - }; const markdown = `# Hello World\n\nThis is **bold** and *italic*.\n\n- Item 1\n- Item 2\n\n\`\`\`js\nconst x = 5;\n\`\`\``; const html = await parseMarkdown(markdown); - if (!html.includes('

') || !html.includes('') || !html.includes('') || !html.includes('
    ') || !html.includes('')) { - throw new Error('Test Failed: HTML output missing required elements.'); + const doc = new DOMParser().parseFromString(html, 'text/html'); + const selectors = ['h1', 'strong', 'em', 'ul', 'code']; + const missing = selectors.find(s => !doc.querySelector(s)); + if (missing) { + throw new Error(`Test Failed: HTML output missing required element: <${missing}>`); } } }; -