8
0
Просмотр исходного кода

Remove istanbule ignore, and provide test which simulate non-supported environment.

Mateusz Samsel 6 лет назад
Родитель
Сommit
93ae266bee

+ 0 - 1
packages/ckeditor5-word-count/src/wordcount.js

@@ -234,7 +234,6 @@ export default class WordCount extends Plugin {
 
 		const wordsMatch = regExpFeatureDetection.isUnicodePropertySupported ?
 			txt.match( new RegExp( '[\\p{L}\\p{N}\\p{M}\\p{Pd}\\p{Pc}]+', 'gu' ) ) :
-			/* istanbul ignore next */
 			txt.match( /[_\-a-zA-Z0-9À-ž]+/gu );
 
 		this.words = ( wordsMatch || [] ).length;

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

@@ -109,6 +109,27 @@ describe( 'WordCount', () => {
 			expect( wordCountPlugin.words ).to.equal( 6 );
 		} );
 
+		describe( 'ES2018 RegExp Unicode property fallback', () => {
+			const originalPropertiesSupport = regExpFeatureDetection.isUnicodePropertySupported;
+
+			before( () => {
+				regExpFeatureDetection.isUnicodePropertySupported = false;
+			} );
+
+			after( () => {
+				regExpFeatureDetection.isUnicodePropertySupported = originalPropertiesSupport;
+			} );
+
+			it( 'should use different regexp when unicode properties are not supported', () => {
+				expect( wordCountPlugin.words ).to.equal( 0 );
+
+				setModelData( model, '<paragraph>hello world.</paragraph>' );
+				wordCountPlugin._calculateWordsAndCharacters();
+
+				expect( wordCountPlugin.words ).to.equal( 2 );
+			} );
+		} );
+
 		describe( 'update event', () => {
 			it( 'fires update event with actual amount of characters and words', () => {
 				const fake = sinon.fake();