Skip to content

Commit

Permalink
chore: [#1615] Fixes problems related to parsing <html>, <head> and <…
Browse files Browse the repository at this point in the history
…body> using DOMParser
  • Loading branch information
capricorn86 committed Nov 19, 2024
1 parent 25053c8 commit 1fb5412
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/happy-dom/src/xml-parser/XMLParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default class XMLParser {
html: HTMLDocumentModeEnum.noTag,
body: HTMLDocumentModeEnum.noTag,
head: HTMLDocumentModeEnum.noTag
}
}
: null;
let newNode: Node | null = null;
let currentNode: Node | null = root;
Expand Down
9 changes: 6 additions & 3 deletions packages/happy-dom/test/dom-parser/DOMParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,18 @@ describe('DOMParser', () => {
expect(newDocument.body.textContent).toBe('here is some html elástica ');
});

it('parses SVGs', () => {
it('Parses SVGs', () => {
const newDocument = domParser.parseFromString(DOMParserSVG, 'image/svg+xml');
expect(new XMLSerializer().serializeToString(newDocument).replace(/[\s]/gm, '')).toBe(
DOMParserSVG.replace(/[\s]/gm, '')
);
});

it('recognises BODY', () => {
const newDocument = domParser.parseFromString('<body><example></example>Example Text</body>', 'text/html');
it('Parses body', () => {
const newDocument = domParser.parseFromString(
'<body><example></example>Example Text</body>',
'text/html'
);
expect(newDocument.body.innerHTML).toBe('<example></example>Example Text');
});
});
Expand Down

0 comments on commit 1fb5412

Please sign in to comment.