From ab4926f1a9af86c65fd2c99c094d24d37e25d1e4 Mon Sep 17 00:00:00 2001 From: SettingDust Date: Tue, 6 Dec 2022 20:17:28 +0800 Subject: [PATCH] test: add test for `parseHTML` --- test/e2e.test.ts | 16 ---------------- test/parse-html.test.ts | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 16 deletions(-) delete mode 100644 test/e2e.test.ts create mode 100644 test/parse-html.test.ts diff --git a/test/e2e.test.ts b/test/e2e.test.ts deleted file mode 100644 index c306ddf..0000000 --- a/test/e2e.test.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { NodeHtmlMarkdown } from '../src'; -import { DOMParser } from 'linkedom'; - - -const html = `

Foo

`; - -describe('E2E', () => { - test('Browser', () => { - __IS_BROWSER__ = true; - globalThis.DOMParser = DOMParser; - const res = new NodeHtmlMarkdown({ - preferNativeParser: true - }).translate(html); - expect(res).toBe(`**F**oo\n\n* Bar`); - }); -}); diff --git a/test/parse-html.test.ts b/test/parse-html.test.ts new file mode 100644 index 0000000..e2ec4e6 --- /dev/null +++ b/test/parse-html.test.ts @@ -0,0 +1,24 @@ +import { parseHTML } from '../src/utilities'; +import { defaultOptions } from '../src/config'; +import { DOMParser } from 'linkedom'; + + +describe('parseHTML', () => { + test('should parse HTML with native parser in browser', () => { + __IS_BROWSER__ = true; + globalThis.DOMParser = DOMParser; + const html = '
test
'; + const parsedHtml = parseHTML(html, { ...defaultOptions, preferNativeParser: true }); + expect(parsedHtml).toBeDefined(); + }); + test('should parse HTML in node when preferNativeParser is true', () => { // This test fails + const html = '
test
'; + const parsedHtml = parseHTML(html, { ...defaultOptions, preferNativeParser: true }); + expect(parsedHtml).toBeDefined(); + }); + test('should parse HTML in node when preferNativeParser is false', () => { + const html = '
test
'; + const parsedHtml = parseHTML(html, defaultOptions); + expect(parsedHtml).toBeDefined(); + }); +});