Skip to content

Commit 35a76be

Browse files
committed
update test cases.
1 parent 2f0a715 commit 35a76be

3 files changed

Lines changed: 67 additions & 3 deletions

File tree

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ validator.isEmail('abc@gmail.com'); // => true
3737
- isChineseTel(str): check if it is a Chinese cell-phone number
3838
- isChineseIdCard(str): check if it is a 18-digit Chinese ID card number
3939

40+
## Test
41+
42+
```
43+
git clone git@github.com:SFantasy/node-validator.git && cd node-validator
44+
45+
[sudo] npm install mocha -g
46+
47+
mocha
48+
```
49+
50+
or
51+
52+
```
53+
npm test
54+
```
55+
4056
## License
4157

4258
The MIT License

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "String validator for more",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "./node_modules/.bin/_mocha"
88
},
99
"repository": {
1010
"type": "git",

test/test.js

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function test(options) {
4040
describe('Validate', function () {
4141

4242
describe('#isEmail', function () {
43-
it('should validate email address', function (done) {
43+
it('should validate email address', function () {
4444
test({
4545
validator: 'isEmail',
4646
valid: [
@@ -54,8 +54,56 @@ describe('Validate', function () {
5454
'@test.com'
5555
]
5656
});
57+
});
58+
});
59+
60+
describe('#isAllChinese', function () {
61+
it('should validate all Chinese characters', function () {
62+
test({
63+
validator: 'isAllChinese',
64+
valid: [
65+
'你好世界'
66+
],
67+
invalid: [
68+
'hello world',
69+
'你好world',
70+
'你好 世界',
71+
'你好123world'
72+
]
73+
});
74+
});
75+
});
76+
77+
describe('#isAllEnglish', function () {
78+
it('should validate all English characters', function () {
79+
test({
80+
validator: 'isAllEnglish',
81+
valid: [
82+
'HelloWorld'
83+
],
84+
invalid: [
85+
'Hello世界',
86+
'你好世界',
87+
'你好123world',
88+
'Hello World'
89+
]
90+
});
91+
});
92+
});
5793

58-
done();
94+
describe('#isAllDigit', function () {
95+
it('should validate all digits', function () {
96+
test({
97+
validator: 'isAllDigit',
98+
valid: [
99+
'12345'
100+
],
101+
invalid: [
102+
'123哈哈',
103+
'HelloWorld33',
104+
'你好世界'
105+
]
106+
});
59107
});
60108
});
61109

0 commit comments

Comments
 (0)