From efc812d9d871a71a676eb954cb0e27df619c18be Mon Sep 17 00:00:00 2001 From: Mateusz Samsel Date: Thu, 11 Jul 2019 09:38:55 +0200 Subject: [PATCH 1/4] Prevent of destroying undefined wordcoutn container. --- src/wordcount.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wordcount.js b/src/wordcount.js index 4221635..4d998ae 100644 --- a/src/wordcount.js +++ b/src/wordcount.js @@ -136,8 +136,10 @@ export default class WordCount extends Plugin { * @inheritDoc */ destroy() { - this._outputView.element.remove(); - this._outputView.destroy(); + if ( this._outputView ) { + this._outputView.element.remove(); + this._outputView.destroy(); + } super.destroy(); } From d16fb48db351cd72b34dd37bd5d1652e1c5d090d Mon Sep 17 00:00:00 2001 From: Mateusz Samsel Date: Thu, 11 Jul 2019 09:49:46 +0200 Subject: [PATCH 2/4] Add unit test for undefined wordcount container. --- tests/wordcount.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/wordcount.js b/tests/wordcount.js index 36099db..b64f84e 100644 --- a/tests/wordcount.js +++ b/tests/wordcount.js @@ -158,6 +158,23 @@ describe( 'WordCount', () => { .then( done ) .catch( done ); } ); + + describe( 'container not created', () => { + let editor; + + beforeEach( () => { + return VirtualTestEditor.create( { + plugins: [ WordCount, Paragraph ] + } ) + .then( _editor => { + editor = _editor; + } ); + } ); + + it( 'should not throw an error', () => { + return editor.destroy(); + } ); + } ); } ); } ); From ae65fbb772cdec035685dad8bf9e3d861532a263 Mon Sep 17 00:00:00 2001 From: Mateusz Samsel Date: Thu, 11 Jul 2019 09:55:38 +0200 Subject: [PATCH 3/4] Fix docs description. --- docs/features/word-count.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/features/word-count.md b/docs/features/word-count.md index e5f3ee6..4e88ff3 100644 --- a/docs/features/word-count.md +++ b/docs/features/word-count.md @@ -92,7 +92,7 @@ ClassicEditor ## Common API The {@link module:word-count/wordcount~WordCount} plugin provides: - * {@link module:word-count/wordcount~WordCount#wordCountContainer} method. It returns a self-updating HTML element which is updated with the current number of words and characters in the editor. There is a possibility to remove "Words" or "Characters" counters with proper configuration of {@link module:word-count/wordcount~WordCountConfig#displayWords} and {@link module:word-count/wordcount~WordCountConfig#displayCharacters}, + * {@link module:word-count/wordcount~WordCount#wordCountContainer} getter. It returns a self-updating HTML element which is updated with the current number of words and characters in the editor. There is a possibility to remove "Words" or "Characters" counters with proper configuration of {@link module:word-count/wordcount~WordCountConfig#displayWords} and {@link module:word-count/wordcount~WordCountConfig#displayCharacters}, * {@link module:word-count/wordcount~WordCount#event:update update event} which is fired whenever the plugins update the number of counted words and characters. There is a possibility to run own callback function with updated values. Please note that update event is throttled. From 46e0c6e2519d032a166c6965f1e35f269e40fa46 Mon Sep 17 00:00:00 2001 From: Mateusz Samsel Date: Thu, 11 Jul 2019 14:31:12 +0200 Subject: [PATCH 4/4] Simplify unit test. --- tests/wordcount.js | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/tests/wordcount.js b/tests/wordcount.js index b64f84e..ff7a258 100644 --- a/tests/wordcount.js +++ b/tests/wordcount.js @@ -159,21 +159,13 @@ describe( 'WordCount', () => { .catch( done ); } ); - describe( 'container not created', () => { - let editor; - - beforeEach( () => { - return VirtualTestEditor.create( { - plugins: [ WordCount, Paragraph ] - } ) - .then( _editor => { - editor = _editor; - } ); - } ); - - it( 'should not throw an error', () => { - return editor.destroy(); - } ); + it( 'should not throw an error if container is not specified', () => { + return VirtualTestEditor.create( { + plugins: [ WordCount, Paragraph ] + } ) + .then( editor => { + return editor.destroy(); + } ); } ); } ); } );