Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,28 @@ describe('c-logger-code-viewer', () => {
expect(renderedCode.textContent).toBe(codeWithAngleBrackets);
});

it('renders the code when Element.replaceChildren is unavailable (Lightning Locker)', async () => {
// Lightning Locker's SecureElement proxy does not implement replaceChildren()
const originalReplaceChildren = Element.prototype.replaceChildren;
Element.prototype.replaceChildren = undefined;
try {
const element = createElement('c-logger-code-viewer', { is: LoggerCodeViewer });
element.language = 'apex';
element.startingLineNumber = '1';
element.targetLineNumber = '1';
element.code = 'System.debug(1);';

document.body.appendChild(element);
await flushPromises();

const renderedCode = element.shadowRoot.querySelector('div.prism-viewer pre code');
expect(renderedCode).toBeTruthy();
expect(renderedCode.textContent).toBe('System.debug(1);');
expect(consoleErrorSpy).not.toHaveBeenCalled();
} finally {
Element.prototype.replaceChildren = originalReplaceChildren;
}
});
it('renders code and logs an aggregated error when loadScript rejects', async () => {
mockLoadScriptImpl = jest.fn(() => Promise.reject(new Error('script-load-failed')));
const element = createElement('c-logger-code-viewer', { is: LoggerCodeViewer });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ export default class LoggerCodeViewer extends LightningElement {
codeElement.classList.add(`language-${this.language}`);
codeElement.textContent = this.code ?? '';
preElement.appendChild(codeElement);
container.replaceChildren(preElement);
// Locker's SecureElement proxy does not implement replaceChildren(), so clear and append instead
container.innerHTML = '';
container.appendChild(preElement);
}

_serializeLoadFailure(failure) {
Expand Down