Skip to content

Commit

Permalink
fix: [capricorn86#1151] Add newline if it's a block/flex element and …
Browse files Browse the repository at this point in the history
…there's more content coming after
  • Loading branch information
karpiuMG committed Feb 28, 2025
1 parent a8bcdd4 commit 71b0837
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/happy-dom/src/nodes/html-element/HTMLElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export default class HTMLElement extends Element {
const textTransform = computedStyle.textTransform;

// Only add newline if it's a block/flex element and there's more content coming after
if ((display === 'block' || display === 'flex') && result) {
if ((display === 'block' || display === 'flex') && result && childElement.innerText) {
result += '\n';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ describe('HTMLElement', () => {
expect(element.innerText).toBe('The quick brown fox\nJumped Over The Lazy Dog');
});

it('It skips svg elements when innerText is used', () => {
it("It skips svg elements when innerText is used and add a newline only if there's more content coming after", () => {
document.body.appendChild(element);
element.innerHTML = '<div><span><svg></svg></span>123</div>';
// notice the lack of closing div tag
element.innerHTML = '<div><span><svg></svg></span>123<div>';
expect(element.innerText).toBe('123');
});
});
Expand Down

0 comments on commit 71b0837

Please sign in to comment.