diff --git a/packages/form-js-playground/src/components/JSONEditor.js b/packages/form-js-playground/src/components/JSONEditor.js index 49b22b33f..7d54ce9d7 100644 --- a/packages/form-js-playground/src/components/JSONEditor.js +++ b/packages/form-js-playground/src/components/JSONEditor.js @@ -101,12 +101,22 @@ export function JSONEditor(options = {}) { function createPlaceholderLinterExtension() { return linter((view) => { + if (!view.dom || !container || !document.body || !domClasses) { + return []; + } + const placeholders = view.dom.querySelectorAll('.cm-placeholder'); - if (placeholders.length > 0) { - domClasses(container, document.body).add(NO_LINT_CLS); - } else { - domClasses(container, document.body).remove(NO_LINT_CLS); + + try { + if (placeholders.length > 0) { + domClasses(container, document.body).add(NO_LINT_CLS); + } else { + domClasses(container, document.body).remove(NO_LINT_CLS); + } + } catch (e) { + console.debug('Failed to update editor classes:', e); } + return []; }); } diff --git a/packages/form-js-playground/test/spec/JSONEditor.spec.js b/packages/form-js-playground/test/spec/JSONEditor.spec.js index 3f494cac8..373e1b75d 100644 --- a/packages/form-js-playground/test/spec/JSONEditor.spec.js +++ b/packages/form-js-playground/test/spec/JSONEditor.spec.js @@ -2,6 +2,19 @@ import { JSONEditor } from '../../src/components/JSONEditor'; import { currentCompletions, startCompletion } from '@codemirror/autocomplete'; describe('JSONEditor', function () { + let testContainer; + + beforeEach(function () { + testContainer = document.createElement('div'); + document.body.appendChild(testContainer); + }); + + afterEach(function () { + if (testContainer && testContainer.parentNode) { + testContainer.parentNode.removeChild(testContainer); + } + }); + describe('#setValue', function () { it('should accept external change', async function () { // given @@ -287,6 +300,7 @@ describe('JSONEditor', function () { const variables = ['foobar', 'baz']; const editor = new JSONEditor(); + editor.attachTo(testContainer); editor.setValue(initialValue); editor.setVariables(variables); @@ -311,6 +325,8 @@ describe('JSONEditor', function () { expect(completionDisplayLabels).to.include('"foobar"'); expect(completionDisplayLabels).to.include('"baz"'); }); + + editor.destroy(); }); it('should suggest property completion after comma', async function () { @@ -319,6 +335,7 @@ describe('JSONEditor', function () { const variables = ['foobar', 'baz']; const editor = new JSONEditor(); + editor.attachTo(testContainer); editor.setValue(initialValue); editor.setVariables(variables); @@ -343,6 +360,8 @@ describe('JSONEditor', function () { expect(completionDisplayLabels).to.include('"foobar"'); expect(completionDisplayLabels).to.include('"baz"'); }); + + editor.destroy(); }); }); });