Skip to content

Commit b76305e

Browse files
committed
Fixed M/C
1 parent a48637c commit b76305e

File tree

9 files changed

+787
-233
lines changed

9 files changed

+787
-233
lines changed

README.md

Lines changed: 80 additions & 59 deletions
Large diffs are not rendered by default.
File renamed without changes.
File renamed without changes.
File renamed without changes.

test/testFunctions.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import assert from 'assert';
2+
import { format } from 'util';
3+
import validator from '../src/index';
4+
5+
export default function test(options) {
6+
const args = options.args || [];
7+
8+
args.unshift(null);
9+
10+
if (options.error) {
11+
options.error.forEach((error) => {
12+
args[0] = error;
13+
14+
try {
15+
assert.throws(() => validator[options.validator](...args));
16+
} catch (err) {
17+
const warning = format(
18+
'validator.%s(%s) passed but should error',
19+
options.validator, args.join(', ')
20+
);
21+
22+
throw new Error(warning);
23+
}
24+
});
25+
}
26+
27+
if (options.valid) {
28+
options.valid.forEach((valid) => {
29+
args[0] = valid;
30+
31+
if (validator[options.validator](...args) !== true) {
32+
const warning = format(
33+
'validator.%s(%s) failed but should have passed',
34+
options.validator, args.join(', ')
35+
);
36+
37+
throw new Error(warning);
38+
}
39+
});
40+
}
41+
42+
if (options.invalid) {
43+
options.invalid.forEach((invalid) => {
44+
args[0] = invalid;
45+
46+
if (validator[options.validator](...args) !== false) {
47+
const warning = format(
48+
'validator.%s(%s) passed but should have failed',
49+
options.validator, args.join(', ')
50+
);
51+
52+
throw new Error(warning);
53+
}
54+
});
55+
}
56+
}
File renamed without changes.

0 commit comments

Comments
 (0)