Skip to content
This repository was archived by the owner on May 31, 2020. It is now read-only.

Commit a5d0954

Browse files
committed
add test for getWordCount and add non-unicode test for getCharCount
1 parent fceb64e commit a5d0954

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

packages/utils/src/__test__/index.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect } from 'chai'
22
import { 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

Comments
 (0)