Skip to content

Commit ffe066d

Browse files
authored
Merge pull request #4217 from Nokel81/fix-dom-renderering-jsdom-v2
Change clearing innerText to using replaceChildren to fix testing using jsdom
2 parents 0b84d17 + 11e9059 commit ffe066d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/browser/renderer/dom/DomRenderer.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,14 @@ export class DomRenderer extends Disposable implements IRenderer {
338338

339339
public clear(): void {
340340
for (const e of this._rowElements) {
341-
e.innerText = '';
341+
/**
342+
* NOTE: This used to be `e.innerText = '';` but that doesn't work when using `jsdom` and `@testing-library/react`
343+
*
344+
* references:
345+
* - https://github.com/testing-library/react-testing-library/issues/1146
346+
* - https://github.com/jsdom/jsdom/issues/1245
347+
*/
348+
e.replaceChildren();
342349
}
343350
}
344351

@@ -349,11 +356,10 @@ export class DomRenderer extends Disposable implements IRenderer {
349356

350357
for (let y = start; y <= end; y++) {
351358
const rowElement = this._rowElements[y];
352-
rowElement.innerText = '';
353359
const row = y + this._bufferService.buffer.ydisp;
354360
const lineData = this._bufferService.buffer.lines.get(row);
355361
const cursorStyle = this._optionsService.rawOptions.cursorStyle;
356-
rowElement.appendChild(this._rowFactory.createRow(lineData!, row, row === cursorAbsoluteY, cursorStyle, cursorX, cursorBlink, this.dimensions.css.cell.width, this._bufferService.cols));
362+
rowElement.replaceChildren(this._rowFactory.createRow(lineData!, row, row === cursorAbsoluteY, cursorStyle, cursorX, cursorBlink, this.dimensions.css.cell.width, this._bufferService.cols));
357363
}
358364
}
359365

0 commit comments

Comments
 (0)