@@ -51,29 +51,19 @@ describe('SchemaLoader', () => {
51
51
} )
52
52
53
53
describe ( 'when external ref exists' , ( ) => {
54
- let response
55
- let server
56
-
57
- beforeAll ( ( ) => {
58
- response = {
54
+ it ( 'should set oprion { ajax: true }' , done => {
55
+ const response = {
59
56
type : 'string' ,
60
57
minLength : 4
61
58
}
62
- server = createFakeServer ( )
59
+ const server = createFakeServer ( )
63
60
server . autoRespond = true
64
61
window . XMLHttpRequest = server . xhr
65
62
server . respondWith ( [
66
63
200 ,
67
64
{ 'Content-Type' : 'application/json' } ,
68
65
JSON . stringify ( response )
69
66
] )
70
- } )
71
-
72
- afterAll ( ( ) => {
73
- server . restore ( )
74
- } )
75
-
76
- it ( 'should set oprion { ajax: true }' , done => {
77
67
fetchUrl =
78
68
document . location . origin + document . location . pathname . toString ( )
79
69
loader = new SchemaLoader ( { ajax : true } )
@@ -92,6 +82,54 @@ describe('SchemaLoader', () => {
92
82
const urls = Object . keys ( loader . refs )
93
83
expect ( urls . length ) . toEqual ( 1 )
94
84
done ( )
85
+ server . restore ( )
86
+ } ,
87
+ fetchUrl ,
88
+ fileBase
89
+ )
90
+ } )
91
+ } )
92
+
93
+ describe ( 'when external relative $ref exists' , ( ) => {
94
+ it ( 'can get refs recursively' , done => {
95
+ const schema1 = {
96
+ type : 'object' ,
97
+ properties : {
98
+ fname : { $ref : '/schema/main.json' } ,
99
+ lname : { $ref : '/schema/main.json' }
100
+ }
101
+ }
102
+ const schema2 = {
103
+ $ref : 'registry/sub.json'
104
+ }
105
+ const schema3 = {
106
+ type : 'string' ,
107
+ minLength : 4
108
+ }
109
+ const server = createFakeServer ( )
110
+ server . autoRespond = true
111
+ window . XMLHttpRequest = server . xhr
112
+ server . respondWith ( '/schema/main.json' , [
113
+ 200 ,
114
+ { 'Content-Type' : 'application/json' } ,
115
+ JSON . stringify ( schema2 )
116
+ ] )
117
+ server . respondWith ( '/schema/registry/sub.json' , [
118
+ 200 ,
119
+ { 'Content-Type' : 'application/json' } ,
120
+ JSON . stringify ( schema3 )
121
+ ] )
122
+ fetchUrl =
123
+ document . location . origin + document . location . pathname . toString ( )
124
+ loader = new SchemaLoader ( { ajax : true } )
125
+ fileBase = loader . _getFileBase ( document . location . toString ( ) )
126
+ loader . load (
127
+ schema1 ,
128
+ schema => {
129
+ console . log ( loader . refs_with_info )
130
+ expect ( Object . keys ( loader . refs ) . length ) . toBe ( 2 )
131
+ done ( )
132
+ server . restore ( )
95
133
} ,
96
134
fetchUrl ,
97
135
fileBase
0 commit comments