@@ -47,19 +47,21 @@ describe('JSON Schema Viewer component', () => {
4747
4848 test ( 'should render empty message if schema is empty' , ( ) => {
4949 ( isSchemaViewerEmpty as jest . Mock ) . mockReturnValue ( true ) ;
50- const wrapper = shallow ( < JsonSchemaViewerComponent schema = { { } } /> ) ;
50+ const wrapper = shallow ( < JsonSchemaViewerComponent schema = { { } } onError = { jest . fn ( ) } /> ) ;
5151 expect ( isSchemaViewerEmpty ) . toHaveBeenCalledWith ( { } ) ;
5252 expect ( wrapper . find ( SchemaTree ) ) . not . toExist ( ) ;
5353 } ) ;
5454
5555 test ( 'should render SchemaView if schema is provided' , ( ) => {
56- const wrapper = shallow ( < JsonSchemaViewerComponent schema = { schema as JSONSchema4 } /> ) ;
56+ const wrapper = shallow ( < JsonSchemaViewerComponent schema = { schema as JSONSchema4 } onError = { jest . fn ( ) } /> ) ;
5757 expect ( isSchemaViewerEmpty ) . toHaveBeenCalledWith ( schema ) ;
5858 expect ( wrapper . find ( SchemaTree ) ) . toExist ( ) ;
5959 } ) ;
6060
6161 test ( 'should not perform full processing in a worker if provided schema has fewer nodes than maxRows' , ( ) => {
62- const wrapper = shallow ( < JsonSchemaViewerComponent schema = { schema as JSONSchema4 } maxRows = { 10 } /> ) ;
62+ const wrapper = shallow (
63+ < JsonSchemaViewerComponent schema = { schema as JSONSchema4 } maxRows = { 10 } onError = { jest . fn ( ) } /> ,
64+ ) ;
6365 expect ( SchemaWorker . prototype . postMessage ) . not . toHaveBeenCalled ( ) ;
6466 expect ( wrapper . instance ( ) ) . toHaveProperty ( 'treeStore.nodes.length' , 4 ) ;
6567 } ) ;
@@ -79,7 +81,7 @@ describe('JSON Schema Viewer component', () => {
7981 ] ,
8082 } ;
8183
82- shallow ( < JsonSchemaViewerComponent schema = { schemaAllOf } maxRows = { 10 } /> ) ;
84+ shallow ( < JsonSchemaViewerComponent schema = { schemaAllOf } maxRows = { 10 } onError = { jest . fn ( ) } /> ) ;
8385
8486 expect ( SchemaWorker . prototype . postMessage ) . toHaveBeenCalledWith ( {
8587 instanceId : expect . any ( String ) ,
@@ -103,13 +105,15 @@ describe('JSON Schema Viewer component', () => {
103105 ] ,
104106 } ;
105107
106- shallow ( < JsonSchemaViewerComponent schema = { schemaAllOf } maxRows = { 10 } mergeAllOf = { false } /> ) ;
108+ shallow ( < JsonSchemaViewerComponent schema = { schemaAllOf } maxRows = { 10 } mergeAllOf = { false } onError = { jest . fn ( ) } /> ) ;
107109
108110 expect ( SchemaWorker . prototype . postMessage ) . not . toHaveBeenCalledWith ( ) ;
109111 } ) ;
110112
111113 test ( 'should pre-render maxRows nodes and perform full processing in a worker if provided schema has more nodes than maxRows' , ( ) => {
112- const wrapper = shallow ( < JsonSchemaViewerComponent schema = { schema as JSONSchema4 } maxRows = { 1 } /> ) ;
114+ const wrapper = shallow (
115+ < JsonSchemaViewerComponent schema = { schema as JSONSchema4 } maxRows = { 1 } onError = { jest . fn ( ) } /> ,
116+ ) ;
113117 expect ( SchemaWorker . prototype . postMessage ) . toHaveBeenCalledWith ( {
114118 instanceId : expect . any ( String ) ,
115119 mergeAllOf : true ,
@@ -152,6 +156,7 @@ describe('JSON Schema Viewer component', () => {
152156 SchemaWorker . prototype . addEventListener . mock . calls [ 0 ] [ 1 ] ( {
153157 data : {
154158 instanceId : SchemaWorker . prototype . postMessage . mock . calls [ 0 ] [ 0 ] . instanceId ,
159+ error : null ,
155160 nodes,
156161 } ,
157162 } ) ;
@@ -161,14 +166,33 @@ describe('JSON Schema Viewer component', () => {
161166
162167 test ( 'should render all nodes on main thread when worker cannot be spawned regardless of maxRows or schema' , ( ) => {
163168 SchemaWorker . prototype . isShim = true ;
164- const wrapper = shallow ( < JsonSchemaViewerComponent schema = { schema as JSONSchema4 } maxRows = { 1 } /> ) ;
169+ const wrapper = shallow (
170+ < JsonSchemaViewerComponent schema = { schema as JSONSchema4 } maxRows = { 1 } onError = { jest . fn ( ) } /> ,
171+ ) ;
165172
166173 expect ( SchemaWorker . prototype . postMessage ) . not . toHaveBeenCalled ( ) ;
167174 expect ( wrapper . instance ( ) ) . toHaveProperty ( 'treeStore.nodes.length' , 4 ) ;
168175 } ) ;
169176
177+ test ( 'should handle exceptions that may occur during full rendering' , ( ) => {
178+ const onError = jest . fn ( ) ;
179+ shallow ( < JsonSchemaViewerComponent schema = { schema as JSONSchema4 } maxRows = { 1 } onError = { onError } /> ) ;
180+
181+ SchemaWorker . prototype . addEventListener . mock . calls [ 0 ] [ 1 ] ( {
182+ data : {
183+ instanceId : SchemaWorker . prototype . postMessage . mock . calls [ 0 ] [ 0 ] . instanceId ,
184+ error : 'error occurred' ,
185+ nodes : null ,
186+ } ,
187+ } ) ;
188+
189+ expect ( onError ) . toHaveBeenCalledWith ( new Error ( 'error occurred' ) ) ;
190+ } ) ;
191+
170192 test ( 'should not apply result of full processing in a worker if instance ids do not match' , ( ) => {
171- const wrapper = shallow ( < JsonSchemaViewerComponent schema = { schema as JSONSchema4 } maxRows = { 0 } /> ) ;
193+ const wrapper = shallow (
194+ < JsonSchemaViewerComponent schema = { schema as JSONSchema4 } maxRows = { 0 } onError = { jest . fn ( ) } /> ,
195+ ) ;
172196 expect ( SchemaWorker . prototype . postMessage ) . toHaveBeenCalledWith ( {
173197 instanceId : expect . any ( String ) ,
174198 mergeAllOf : true ,
0 commit comments