Selaa lähdekoodia

Add unit test.

Mateusz Samsel 6 vuotta sitten
vanhempi
commit
4e4c9069d5
1 muutettua tiedostoa jossa 24 lisäystä ja 0 poistoa
  1. 24 0
      packages/ckeditor5-word-count/tests/wordcount.js

+ 24 - 0
packages/ckeditor5-word-count/tests/wordcount.js

@@ -148,6 +148,30 @@ describe( 'WordCount', () => {
 				sinon.assert.calledWithExactly( fake, sinon.match.any, { words: 2, characters: 12 } );
 			} );
 		} );
+
+		describe( 'immediate access to values', () => {
+			it( 'should get updated values regardless of update\'s event status', () => {
+				setModelData( model, '<paragraph><$text foo="true">Hello</$text> world.</paragraph>' );
+
+				expect( wordCountPlugin.words ).to.equal( 2 );
+				expect( wordCountPlugin.characters ).to.equal( 12 );
+
+				setModelData( model, '<paragraph><$text foo="true">Hello</$text> world</paragraph>' );
+
+				expect( wordCountPlugin.words ).to.equal( 2 );
+				expect( wordCountPlugin.characters ).to.equal( 11 );
+
+				setModelData( model, '<paragraph><$text foo="true">Hello</$text></paragraph>' );
+
+				expect( wordCountPlugin.words ).to.equal( 1 );
+				expect( wordCountPlugin.characters ).to.equal( 5 );
+
+				setModelData( model, '' );
+
+				expect( wordCountPlugin.words ).to.equal( 0 );
+				expect( wordCountPlugin.characters ).to.equal( 0 );
+			} );
+		} );
 	} );
 
 	describe( 'self-updating element', () => {