Skip to content

Commit

Permalink
test: add test for parseHTML
Browse files Browse the repository at this point in the history
  • Loading branch information
SettingDust committed Dec 6, 2022
1 parent c7fd8ff commit 0ec03d2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
16 changes: 0 additions & 16 deletions test/e2e.test.ts

This file was deleted.

26 changes: 26 additions & 0 deletions test/parse-html.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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 = <typeof globalThis.DOMParser>DOMParser;
const html = '<div>test</div>';
const parsedHtml = parseHTML(html, { ...defaultOptions, preferNativeParser: true });
expect(parsedHtml).toBeDefined();
__IS_BROWSER__ = false;
globalThis.DOMParser = <typeof globalThis.DOMParser><unknown>undefined;
});
test('should parse HTML in node when preferNativeParser is true', () => { // This test fails
const html = '<div>test</div>';
const parsedHtml = parseHTML(html, { ...defaultOptions, preferNativeParser: true });
expect(parsedHtml).toBeDefined();
});
test('should parse HTML in node when preferNativeParser is false', () => {
const html = '<div>test</div>';
const parsedHtml = parseHTML(html, defaultOptions);
expect(parsedHtml).toBeDefined();
});
});

0 comments on commit 0ec03d2

Please sign in to comment.