diff --git a/src/js/control/textarea.tinymce.js b/src/js/control/textarea.tinymce.js index bcd52bd4f..7420f5b64 100644 --- a/src/js/control/textarea.tinymce.js +++ b/src/js/control/textarea.tinymce.js @@ -101,14 +101,14 @@ export default class controlTinymce extends controlTextarea { const afterInit = function (inst) { // Set userData if (copiedData) { - inst.setContent(copiedData) + inst[0].setContent(copiedData) } else if (userData) { - inst.setContent(userData) + inst[0].setContent(userData) } } setTimeout(() => { - // initialise the editor + // initialise the editor within a timeout so that the main thread can continue while tinymce initialises window.tinymce.init(options).then(afterInit) }, 0) } diff --git a/tests/control/textarea.test.js b/tests/control/textarea.test.js index 9dfe8ae47..095519cba 100644 --- a/tests/control/textarea.test.js +++ b/tests/control/textarea.test.js @@ -3,10 +3,6 @@ import controlTinymce from '../../src/js/control/textarea.tinymce' import controlQuill from '../../src/js/control/textarea.quill' import { getScripts, getStyles, isCached } from '../../src/js/utils' -const sleep = milliseconds => { - return new Promise(resolve => setTimeout(resolve, milliseconds)) -} - const loadResources = async (js, css) => { if (css) { getStyles(css) @@ -59,6 +55,7 @@ describe('Test building text variations and subtypes', () => { 'name': 'tinymce-elem', 'access': false, 'subtype': 'tinymce', + userData: ['AValue'], }, false) controlInstance.configure() const element = controlInstance.build() @@ -71,9 +68,21 @@ describe('Test building text variations and subtypes', () => { expect(window.tinymce).not.toBeUndefined() controlInstance.onRender() - await sleep(2000) - expect(window.tinymce.get('tinymce-elem')).not.toBeNull() - }) + //Await tinymce initialisation, this can take many seconds + await (new Promise(resolve => { + const timer = setInterval(() => { + const tinyInstance = window.tinymce.get('tinymce-elem') + if (tinyInstance !== null && tinyInstance.initialized) { + clearTimeout(timer) + resolve() + } + }, 500) + })) + const tinyInstance = window.tinymce.get('tinymce-elem') + expect(tinyInstance).not.toBeNull() + expect(tinyInstance.initialized).toBeTruthy() + expect(tinyInstance.getContent()).toBe('

AValue

') + },20000) //Longer timeout for tinymce initialisation test('can render Quill', async () => { const controlInstance = new controlQuill({