@@ -1143,6 +1143,57 @@ describe("traverse", () => {
1143
1143
testCalls ( mockMutation , testSchema . properties . foo . items [ 0 ] , false , 3 ) ;
1144
1144
testCalls ( mockMutation , testSchema . properties . foo . items [ 1 ] , false , 4 ) ;
1145
1145
} ) ;
1146
+
1147
+ it ( "handles basic cycles when bfs is true" , ( ) => {
1148
+ const schema = { type : "object" , properties : { foo : { } } } as any ;
1149
+ schema . properties . foo = schema ;
1150
+ const mockMutation = jest . fn ( ( s ) => s ) ;
1151
+
1152
+ traverse ( schema as JSONSchema , mockMutation , { bfs : true } ) ;
1153
+
1154
+ expect ( mockMutation ) . toHaveBeenCalledTimes ( 1 ) ;
1155
+ } ) ;
1156
+
1157
+ it ( "handles chained cycles when bfs is true" , ( ) => {
1158
+ const schema = {
1159
+ title : "1" ,
1160
+ type : "object" ,
1161
+ properties : {
1162
+ foo : {
1163
+ title : "2" ,
1164
+ items : [
1165
+ {
1166
+ title : "3" ,
1167
+ type : "array" ,
1168
+ items : { title : "4" } ,
1169
+ } ,
1170
+ ] ,
1171
+ } ,
1172
+ } ,
1173
+ } as any ;
1174
+ schema . properties . foo . items [ 0 ] . items = schema ;
1175
+ const mockMutation = jest . fn ( ( s ) => s ) ;
1176
+
1177
+ traverse ( schema as JSONSchema , mockMutation , { bfs : true } ) ;
1178
+
1179
+ expect ( mockMutation ) . toHaveBeenCalledTimes ( 3 ) ;
1180
+ } ) ;
1181
+
1182
+ it ( "bfs still calls mutation for root cycles when skipFirstMutation is true" , ( ) => {
1183
+ const schema : any = { title : "a" , items : { } } ;
1184
+ schema . items = schema ;
1185
+ const mockMutation = jest . fn ( ( s ) => s ) ;
1186
+
1187
+ traverse ( schema as JSONSchema , mockMutation , { bfs : true , skipFirstMutation : true , mutable : true } ) ;
1188
+
1189
+ expect ( mockMutation ) . toHaveBeenCalledTimes ( 1 ) ;
1190
+ expect ( mockMutation ) . toHaveBeenCalledWith (
1191
+ schema ,
1192
+ true ,
1193
+ expect . any ( String ) ,
1194
+ schema
1195
+ ) ;
1196
+ } ) ;
1146
1197
} ) ;
1147
1198
describe ( "Mutability settings" , ( ) => {
1148
1199
it ( "defaults to being immutable" , ( ) => {
0 commit comments