11import { expect } from 'chai'
22import { EditorState , ContentState } from 'draft-js'
3- import { getCharCount } from '../index'
3+ import { getCharCount , getWordCount } from '../index'
44
5- describe ( 'char Counter' , ( ) => {
5+ describe ( 'char Counter(non-unicode) ' , ( ) => {
66 const createEditorStateFromText = text => {
77 const contentState = ContentState . createFromText ( text )
88 return EditorState . createWithContent ( contentState )
@@ -15,3 +15,31 @@ describe('char Counter', () => {
1515 expect ( result ) . to . equal ( 3 )
1616 } )
1717} )
18+
19+ describe ( 'char Counter(unicode)' , ( ) => {
20+ const createEditorStateFromText = text => {
21+ const contentState = ContentState . createFromText ( text )
22+ return EditorState . createWithContent ( contentState )
23+ }
24+
25+ it ( 'create editorState and counts 1 char' , ( ) => {
26+ const editorState = createEditorStateFromText ( '一' )
27+
28+ const result = getCharCount ( editorState )
29+ expect ( result ) . to . equal ( 1 )
30+ } )
31+ } )
32+
33+ describe ( 'word Counter' , ( ) => {
34+ const createEditorStateFromText = text => {
35+ const contentState = ContentState . createFromText ( text )
36+ return EditorState . createWithContent ( contentState )
37+ }
38+
39+ it ( 'create editorState and counts 3 word' , ( ) => {
40+ const editorState = createEditorStateFromText ( 'One two three' )
41+
42+ const result = getWordCount ( editorState )
43+ expect ( result ) . to . equal ( 3 )
44+ } )
45+ } )
0 commit comments