@@ -12,6 +12,102 @@ describe('Validator', function () {
12
12
beforeEach ( function ( ) {
13
13
validator = new Validator ( ) ;
14
14
} ) ;
15
+ describe ( 'Validator#unresolvedRefs' , function ( ) {
16
+ it ( 'initial value' , function ( ) {
17
+ assert . deepStrictEqual ( validator . unresolvedRefs , [ ] ) ;
18
+ } ) ;
19
+ it ( 'addSchema' , function ( ) {
20
+ validator . addSchema ( {
21
+ id : 'http://example.com/base.json' ,
22
+ items : {
23
+ $ref : 'item.json' ,
24
+ } ,
25
+ } ) ;
26
+ assert . deepStrictEqual ( validator . unresolvedRefs , [ 'http://example.com/item.json' ] ) ;
27
+ } ) ;
28
+ } ) ;
29
+ describe ( 'Validator#addSchema' , function ( ) {
30
+ it ( 'argument schema must be a schema: object' , function ( ) {
31
+ validator . addSchema ( { } , 'http://example.com/base.json' ) ;
32
+ assert . deepStrictEqual ( validator . schemas [ 'http://example.com/base.json' ] , { } ) ;
33
+ } ) ;
34
+ // TODO: held for major version upgrade
35
+ it . skip ( 'argument schema must be a schema: true' , function ( ) {
36
+ validator . addSchema ( true , 'http://example.com/base.json' ) ;
37
+ assert . deepStrictEqual ( validator . schemas [ 'http://example.com/base.json' ] , true ) ;
38
+ } ) ;
39
+ // TODO: held for major version upgrade
40
+ it . skip ( 'argument schema must be a schema: false' , function ( ) {
41
+ validator . addSchema ( false , 'http://example.com/base.json' ) ;
42
+ assert . deepStrictEqual ( validator . schemas [ 'http://example.com/base.json' ] , false ) ;
43
+ } ) ;
44
+ it ( 'argument schema must be a schema: null' , function ( ) {
45
+ var res = validator . addSchema ( undefined , 'http://example.com/base.json' ) ;
46
+ assert . strictEqual ( res , null ) ;
47
+ assert ( ! ( 'http://example.com/base.json' in validator . schemas ) ) ;
48
+ } ) ;
49
+ it ( 'argument schema must be a schema: undefined' , function ( ) {
50
+ var res = validator . addSchema ( undefined , 'http://example.com/base.json' ) ;
51
+ assert . strictEqual ( res , null ) ;
52
+ assert ( ! ( 'http://example.com/base.json' in validator . schemas ) ) ;
53
+ } ) ;
54
+ // TODO: held for major version upgrade
55
+ it . skip ( 'argument schema must not be a number' , function ( ) {
56
+ assert . throws ( function ( ) {
57
+ validator . addSchema ( 1 , 'http://example.com/base.json' ) ;
58
+ } , function ( err ) {
59
+ assert ( err instanceof Error ) ;
60
+ return true ;
61
+ } ) ;
62
+ } ) ;
63
+ // TODO: held for major version upgrade
64
+ it . skip ( 'argument schema must not be a string' , function ( ) {
65
+ assert . throws ( function ( ) {
66
+ validator . addSchema ( "schema" , 'http://example.com/base.json' ) ;
67
+ } , function ( err ) {
68
+ assert ( err instanceof Error ) ;
69
+ return true ;
70
+ } ) ;
71
+ } ) ;
72
+ // TODO: held for major version upgrade
73
+ it . skip ( 'argument schema must not be null' , function ( ) {
74
+ assert . throws ( function ( ) {
75
+ validator . addSchema ( null , 'http://example.com/base.json' ) ;
76
+ } , function ( err ) {
77
+ assert ( err instanceof Error ) ;
78
+ return true ;
79
+ } ) ;
80
+ } ) ;
81
+ // TODO: held for major version upgrade
82
+ it . skip ( 'argument schema must not be undefined' , function ( ) {
83
+ assert . throws ( function ( ) {
84
+ validator . addSchema ( undefined , 'http://example.com/base.json' ) ;
85
+ } , function ( err ) {
86
+ assert ( err instanceof Error ) ;
87
+ return true ;
88
+ } ) ;
89
+ } ) ;
90
+ it ( 'addSchema(schema) with absolute id' , function ( ) {
91
+ validator . addSchema ( {
92
+ id : 'http://example.com/base.json' ,
93
+ } ) ;
94
+ assert . deepStrictEqual ( validator . unresolvedRefs , [ ] ) ;
95
+ } ) ;
96
+ it ( 'addSchema(schema) with absolute $id' , function ( ) {
97
+ validator . addSchema ( {
98
+ $id : 'http://example.com/base.json' ,
99
+ } ) ;
100
+ assert . deepStrictEqual ( validator . unresolvedRefs , [ ] ) ;
101
+ } ) ;
102
+ it ( 'addSchema(schema, base) with relative id' , function ( ) {
103
+ validator . addSchema ( { id : 'base.json' } , 'http://example.com/index.html' ) ;
104
+ assert ( 'http://example.com/base.json' in validator . schemas ) ;
105
+ } ) ;
106
+ it ( 'addSchema(schema, base) with relative $id' , function ( ) {
107
+ validator . addSchema ( { $id : 'base.json' } , 'http://example.com/index.html' ) ;
108
+ assert ( 'http://example.com/base.json' in validator . schemas ) ;
109
+ } ) ;
110
+ } ) ;
15
111
describe ( 'Validator#validate' , function ( ) {
16
112
it ( 'schema may be an object' , function ( ) {
17
113
var res = validator . validate ( true , { } ) ;
@@ -33,6 +129,14 @@ describe('Validator', function () {
33
129
return true ;
34
130
} ) ;
35
131
} ) ;
132
+ it ( 'schema cannot be undefined' , function ( ) {
133
+ assert . throws ( function ( ) {
134
+ validator . validate ( true , undefined ) ;
135
+ } , function ( err ) {
136
+ assert ( err instanceof SchemaError ) ;
137
+ return true ;
138
+ } ) ;
139
+ } ) ;
36
140
it ( 'schema cannot be a string' , function ( ) {
37
141
assert . throws ( function ( ) {
38
142
validator . validate ( true , "string" ) ;
@@ -41,5 +145,14 @@ describe('Validator', function () {
41
145
return true ;
42
146
} ) ;
43
147
} ) ;
148
+ it ( 'options may be undefined' , function ( ) {
149
+ validator . validate ( null , true , undefined ) ;
150
+ } ) ;
151
+ it ( 'options may be null' , function ( ) {
152
+ validator . validate ( null , true , null ) ;
153
+ } ) ;
154
+ it ( 'options.base must be a string' , function ( ) {
155
+ validator . validate ( null , true , null ) ;
156
+ } ) ;
44
157
} ) ;
45
158
} ) ;
0 commit comments