-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
48 lines (39 loc) · 1.01 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import {ok} from 'assert';
import Shape from '../src/Shape';
async function run() {
console.log('testing shape');
const validData = {
x: 1,
y: 2
};
const dataWithExtraKey = {
x: 1,
y: 2,
z: 3
};
const invalidData = {
x: 1,
y: 1
};
const validation = new Shape({
x: (x) => x === 1 ? null : 'invalid',
y: (y) => new Promise((resolve) => {
setTimeout(() => resolve(2), 300);
}).then((val) => y === val ? null : 'invalid')
});
console.log('testing valid data');
const noErr = await validation.errors(validData);
ok(noErr === null);
console.log('testing data with extra key');
const extraKeyErr = await validation.errors(dataWithExtraKey);
ok(extraKeyErr.x === null);
ok(extraKeyErr.y === null);
ok(extraKeyErr.z === 'invalid key');
console.log('testing invalid data');
const invalidDataErr = await validation.errors(invalidData);
ok(invalidDataErr.x === null);
ok(invalidDataErr.y === 'invalid');
}
if (require.main === module) {
run();
}