-
Notifications
You must be signed in to change notification settings - Fork 0
/
tester.js
43 lines (36 loc) 路 1 KB
/
tester.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
// How not to do testing.
// I'm just too lazy. Deal with it folks.
// I'd love getting a PR that implements proper unit testing for Schemr.
const { Schemr, check } = require('schemr');
const testSchema = new Schemr('human-being', {
name: Schemr.field,
age: Schemr.field,
job: Schemr.field,
});
console.log(testSchema.getName());
//=> human-being
console.log(testSchema.getFields());
//=> { name: 'SchemrField', age: 'SchemrField', job: 'SchemrField' }
console.log(testSchema.toJSON());
/*=>
{
"name": "human-being",
"fields": {
"name": "SchemrField",
"age": "SchemrField",
"job": "SchemrField"
}
}
*/
const testData = {
name: 'Mark',
extraFieldForNoReason: false,
};
const checkedObject = check(testSchema, testData);
console.log(checkedObject);
//=> { name: 'Mark', age: 21, job: undefined }
const checkedObject2 = check(testSchema, testData, {
replaceEmptyFieldsWith: 'unfilled',
});
console.log(checkedObject2);
//=> { name: 'Mark', age: 'unfilled', job: 'unfilled' }