Skip to content

Commit cd5d571

Browse files
committed
Adding tests for the TextHelper
1 parent 3d90439 commit cd5d571

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "A react markdown-editor like Stackoverflow and Github",
55
"main": "index.js",
66
"scripts": {
7+
"test": "mocha --timeout 15000 --compilers js:babel-register ./test/*Spec.js",
78
"start": "cross-env NODE_ENV=development babel-node ./demo/server.js",
89
"build": "cross-env NODE_ENV=production gulp build"
910
},
@@ -30,6 +31,7 @@
3031
"babel-preset-react-hmre": "^1.1.1",
3132
"babel-preset-stage-0": "^6.16.0",
3233
"bootstrap": "^4.0.0-alpha.5",
34+
"chai": "^3.5.0",
3335
"colors": "^1.1.2",
3436
"cross-env": "^3.1.3",
3537
"css-loader": "^0.26.0",
@@ -41,6 +43,7 @@
4143
"gulp-cli": "^1.2.2",
4244
"less": "^2.7.1",
4345
"less-loader": "^2.2.3",
46+
"mocha": "^3.2.0",
4447
"node-sass": "^3.13.0",
4548
"react-hot-loader": "^3.0.0-beta.6",
4649
"react-redux": "^4.4.6",

test/TextHelperSpec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { assert } from 'chai';
2+
import { insertText } from '../src/TextHelper';
3+
4+
describe("TextHelperSpec.js", function () {
5+
describe('insertText', function () {
6+
it('should work mid-string', function () {
7+
var text = insertText('bob school', 'went to ', 4);
8+
assert.strictEqual(text, 'bob went to school');
9+
});
10+
it('should work in the start', function () {
11+
var text = insertText('went to school', 'bob ', 0);
12+
assert.strictEqual(text, 'bob went to school');
13+
});
14+
it('should work in the end', function () {
15+
var text = insertText('bob went to', ' school', 11);
16+
assert.strictEqual(text, 'bob went to school');
17+
});
18+
19+
it('should work with a position greater than the max', function () {
20+
var text = insertText('bob went to', ' school', 20);
21+
assert.strictEqual(text, 'bob went to school');
22+
});
23+
})
24+
});

0 commit comments

Comments
 (0)