Skip to content

Commit 6f614ba

Browse files
test(module): add ES Module test for client html-dom-parser.mjs
1 parent 7de506c commit 6f614ba

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lib/client/domparser.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ var parseFromString = function () {
2020
);
2121
};
2222

23+
var DOMParser = typeof window === 'object' && window.DOMParser;
24+
2325
/**
2426
* DOMParser (performance: slow).
2527
*
2628
* @see https://developer.mozilla.org/docs/Web/API/DOMParser#Parsing_an_SVG_or_HTML_document
2729
*/
28-
if (typeof window.DOMParser === 'function') {
29-
var domParser = new window.DOMParser();
30+
if (typeof DOMParser === 'function') {
31+
var domParser = new DOMParser();
3032
var mimeType = 'text/html';
3133

3234
/**
@@ -52,7 +54,7 @@ if (typeof window.DOMParser === 'function') {
5254
*
5355
* @see https://developer.mozilla.org/docs/Web/API/DOMImplementation/createHTMLDocument
5456
*/
55-
if (document.implementation) {
57+
if (typeof document === 'object' && document.implementation) {
5658
var doc = document.implementation.createHTMLDocument();
5759

5860
/**
@@ -79,7 +81,9 @@ if (document.implementation) {
7981
*
8082
* @see https://developer.mozilla.org/docs/Web/HTML/Element/template
8183
*/
82-
var template = document.createElement('template');
84+
var template =
85+
typeof document === 'object' ? document.createElement('template') : {};
86+
8387
var parseFromTemplate;
8488

8589
if (template.content) {

test/module/index.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import assert from 'assert';
22
import HTMLDOMParser from '../../index.mjs';
3+
import HTMLDOMParserClient from '../../lib/client/html-to-dom.mjs';
34

45
assert.strictEqual(typeof HTMLDOMParser, 'function');
6+
assert.strictEqual(typeof HTMLDOMParserClient, 'function');

0 commit comments

Comments
 (0)