You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
post1.text='this is a great post about hello world';// should pass
11
+
post1.rating=10;// should pass
12
+
post1.email='info@google.com';// should pass
13
+
post1.site='google.com';// should pass
14
+
post1.createDate=newDate();// should pass
15
+
16
+
console.log(validator.validate(Post,post1));// should pass completely, e.g. return empty array
17
+
18
+
letpost2=newPost();
19
+
post2.title='Hello';// should not pass
20
+
post2.text='this is a great post about hell world';// should not pass
21
+
post2.rating=11;// should not pass
22
+
post2.email='google.com';// should not pass
23
+
post2.site='googlecom';// should not pass
24
+
// should not pass because date property is missing
25
+
26
+
console.log(validator.validate(Post,post2));// should not pass completely, must return array of ValidationError-s
27
+
28
+
// Sample2. using validation options to skip properties that are not defined
29
+
30
+
letpost3=newPost();
31
+
post3.title='Hello';// should not pass
32
+
post3.text='this is a great post about hell world';// should not pass
33
+
post3.rating=11;// should not pass
34
+
post3.email='google.com';// should not pass
35
+
post3.site='googlecom';// should not pass
36
+
37
+
console.log(validator.validate(Post,post3,{skipMissingProperties: true}));// should not pass, but returned ValidationError-s should not have error about date field
38
+
39
+
letpost4=newPost();
40
+
post4.title='Hello world';// should pass
41
+
post4.text='this is a great post about hello world';// should pass
42
+
post4.rating=10;// should pass
43
+
post4.email='info@google.com';// should pass
44
+
post4.site='google.com';// should pass
45
+
46
+
console.log(validator.validate(Post,post4,{skipMissingProperties: true}));// should pass even if date is not set
47
+
48
+
// Sample3. using validation groups
49
+
50
+
letpost5=newPost();
51
+
post5.title='Hello world';// should pass
52
+
post5.text='this is a great post about hello world';// should pass
53
+
post5.rating=10;// should pass
54
+
post5.email='info@google.com';// should pass
55
+
post5.site='google.com';// should pass
56
+
57
+
console.log(validator.validate(Post,post5,{skipMissingProperties: true}));// should pass even if date is not set
0 commit comments