-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7fd8ff
commit 0ec03d2
Showing
2 changed files
with
26 additions
and
16 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |