@@ -42,20 +42,26 @@ describe("ErrorNode", () => {
4242 } as RenderReturnNode )
4343 ) . toEqual ( {
4444 properties : {
45+ errorTitle : "UNKNOWN_ERROR" ,
4546 dataset : {
4647 errorBoundary : "" ,
4748 } ,
4849 style : {
4950 color : "var(--color-error)" ,
5051 } ,
51- textContent : "UNKNOWN_ERROR: Error: oops" ,
5252 } ,
5353 return : {
5454 tag : 1 ,
5555 } ,
5656 runtimeContext : null ,
5757 tag : 2 ,
5858 type : "div" ,
59+ child : expect . objectContaining ( {
60+ type : "div" ,
61+ properties : {
62+ textContent : "UNKNOWN_ERROR: Error: oops" ,
63+ } ,
64+ } ) ,
5965 } ) ;
6066 } ) ;
6167
@@ -72,20 +78,26 @@ describe("ErrorNode", () => {
7278 )
7379 ) . toEqual ( {
7480 properties : {
81+ errorTitle : "NO_PERMISSION" ,
7582 dataset : {
7683 errorBoundary : "" ,
7784 } ,
7885 style : {
7986 color : "var(--color-error)" ,
8087 } ,
81- textContent : "NO_PERMISSION: HttpResponseError: Forbidden" ,
8288 } ,
8389 return : {
8490 tag : 1 ,
8591 } ,
8692 runtimeContext : null ,
8793 tag : 2 ,
8894 type : "div" ,
95+ child : expect . objectContaining ( {
96+ type : "div" ,
97+ properties : {
98+ textContent : "NO_PERMISSION: HttpResponseError: Forbidden" ,
99+ } ,
100+ } ) ,
89101 } ) ;
90102 } ) ;
91103
@@ -96,20 +108,26 @@ describe("ErrorNode", () => {
96108 } as RenderReturnNode )
97109 ) . toEqual ( {
98110 properties : {
111+ errorTitle : "NETWORK_ERROR" ,
99112 dataset : {
100113 errorBoundary : "" ,
101114 } ,
102115 style : {
103116 color : "var(--color-error)" ,
104117 } ,
105- textContent : "NETWORK_ERROR: BrickLoadError: oops" ,
106118 } ,
107119 return : {
108120 tag : 1 ,
109121 } ,
110122 runtimeContext : null ,
111123 tag : 2 ,
112124 type : "div" ,
125+ child : expect . objectContaining ( {
126+ type : "div" ,
127+ properties : {
128+ textContent : "NETWORK_ERROR: BrickLoadError: oops" ,
129+ } ,
130+ } ) ,
113131 } ) ;
114132 } ) ;
115133
@@ -214,20 +232,26 @@ describe("ErrorNode", () => {
214232
215233 expect ( await promise ) . toEqual ( {
216234 properties : {
235+ errorTitle : "LICENSE_EXPIRED" ,
217236 dataset : {
218237 errorBoundary : "" ,
219238 } ,
220239 style : {
221240 color : "var(--color-error)" ,
222241 } ,
223- textContent : "LICENSE_EXPIRED: HttpResponseError: Bad Request" ,
224242 } ,
225243 return : {
226244 tag : 1 ,
227245 } ,
228246 runtimeContext : null ,
229247 tag : 2 ,
230248 type : "div" ,
249+ child : expect . objectContaining ( {
250+ type : "div" ,
251+ properties : {
252+ textContent : "LICENSE_EXPIRED: HttpResponseError: Bad Request" ,
253+ } ,
254+ } ) ,
231255 } ) ;
232256
233257 expect ( consoleError ) . toBeCalledTimes ( 1 ) ;
@@ -263,7 +287,7 @@ describe("ErrorNode", () => {
263287 type : "eo-link" ,
264288 properties : {
265289 textContent : "GO_BACK_HOME" ,
266- url : "/" ,
290+ href : "/" ,
267291 } ,
268292 events : undefined ,
269293 } ) ,
@@ -298,7 +322,7 @@ describe("ErrorNode", () => {
298322 type : "eo-link" ,
299323 properties : {
300324 textContent : "GO_BACK_HOME" ,
301- url : "/" ,
325+ href : "/" ,
302326 } ,
303327 events : undefined ,
304328 } ) ,
@@ -320,20 +344,85 @@ describe("ErrorNode", () => {
320344 )
321345 ) . toEqual ( {
322346 properties : {
347+ errorTitle : "APP_NOT_FOUND" ,
323348 dataset : {
324349 errorBoundary : "" ,
325350 } ,
326351 style : {
327352 color : "var(--color-error)" ,
328353 } ,
329- textContent : "APP_NOT_FOUND" ,
330354 } ,
331355 return : {
332356 tag : 1 ,
333357 } ,
334358 runtimeContext : null ,
335359 tag : 2 ,
336360 type : "div" ,
361+ child : expect . objectContaining ( {
362+ type : "div" ,
363+ properties : {
364+ textContent : "APP_NOT_FOUND" ,
365+ } ,
366+ } ) ,
337367 } ) ;
338368 } ) ;
339369} ) ;
370+
371+ describe ( "with default error brick" , ( ) => {
372+ beforeAll ( ( ) => {
373+ customElements . define (
374+ "easyops-default-error" ,
375+ class extends HTMLElement { }
376+ ) ;
377+ } ) ;
378+
379+ test ( "page level with script error and default error brick" , async ( ) => {
380+ const consoleError = jest . spyOn ( console , "error" ) . mockReturnValue ( ) ;
381+ const script = document . createElement ( "script" ) ;
382+ script . src = "fail.js" ;
383+ const scriptError = new Event ( "error" ) ;
384+ Object . defineProperty ( scriptError , "target" , { value : script } ) ;
385+ mockedLoadBricks . mockRejectedValueOnce ( new Error ( "oops" ) ) ;
386+
387+ expect (
388+ await ErrorNode (
389+ scriptError ,
390+ {
391+ tag : RenderTag . ROOT ,
392+ } as RenderReturnNode ,
393+ true
394+ )
395+ ) . toEqual ( {
396+ properties : {
397+ errorTitle : "NETWORK_ERROR" ,
398+ dataset : {
399+ errorBoundary : "" ,
400+ } ,
401+ style : {
402+ color : "var(--color-error)" ,
403+ } ,
404+ } ,
405+ return : {
406+ tag : 1 ,
407+ } ,
408+ runtimeContext : null ,
409+ tag : 2 ,
410+ type : "easyops-default-error" ,
411+ child : expect . objectContaining ( {
412+ type : "div" ,
413+ properties : {
414+ textContent : "http://localhost/fail.js" ,
415+ } ,
416+ sibling : expect . objectContaining ( {
417+ type : "a" ,
418+ slotId : "link" ,
419+ properties : {
420+ textContent : "RELOAD" ,
421+ href : "http://localhost/" ,
422+ } ,
423+ } ) ,
424+ } ) ,
425+ } ) ;
426+ consoleError . mockRestore ( ) ;
427+ } ) ;
428+ } ) ;
0 commit comments