From 44525063bceccceecaff6ed74bf1912e5b22d8ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Wed, 6 Feb 2019 10:36:50 +0100 Subject: [PATCH] do not throw warn if content is null --- packages/tiptap/src/Editor.js | 4 ++++ packages/tiptap/test/Editor.spec.js | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/packages/tiptap/src/Editor.js b/packages/tiptap/src/Editor.js index 20f89d5e..984fa110 100644 --- a/packages/tiptap/src/Editor.js +++ b/packages/tiptap/src/Editor.js @@ -177,6 +177,10 @@ export default class Editor { } createDocument(content) { + if (content === null) { + return this.schema.nodeFromJSON(this.options.emptyDocument) + } + if (typeof content === 'object') { try { return this.schema.nodeFromJSON(content) diff --git a/packages/tiptap/test/Editor.spec.js b/packages/tiptap/test/Editor.spec.js index ec9a4c84..b3ae8b9a 100644 --- a/packages/tiptap/test/Editor.spec.js +++ b/packages/tiptap/test/Editor.spec.js @@ -25,6 +25,14 @@ test('create editor', () => { expect(editor).toBeDefined() }) +test('check empty content (null)', () => { + const editor = new Editor({ + content: null, + }) + + expect(editor.getHTML()).toEqual('

') +}) + test('check invalid content (JSON)', () => { const editor = new Editor({ content: { thisIsNotAValidDocument: true },