@@ -7,15 +7,9 @@ import { render } from '@testing-library/react';
77import ErrorBoundary , { ErrorBoundaryProps } from '../../../lib/components/error-boundary' ;
88import { BuiltInErrorBoundaryProps } from '../../../lib/components/error-boundary/interfaces' ;
99import { BuiltInErrorBoundary } from '../../../lib/components/error-boundary/internal' ;
10- import { refreshPage } from '../../../lib/components/error-boundary/utils' ;
1110import TestI18nProvider from '../../../lib/components/i18n/testing' ;
1211import createWrapper from '../../../lib/components/test-utils/dom' ;
1312
14- jest . mock ( '../../../lib/components/error-boundary/utils' , ( ) => ( {
15- ...jest . requireActual ( '../../../lib/components/error-boundary/utils' ) ,
16- refreshPage : jest . fn ( ) ,
17- } ) ) ;
18-
1913type RenderProps = Omit <
2014 Partial < ErrorBoundaryProps > & { i18nProvider ?: Record < string , Record < string , string > > } & {
2115 [ key : `data-${string } `] : string ;
@@ -618,10 +612,39 @@ describe('built-in error boundaries', () => {
618612} ) ;
619613
620614describe ( 'default behaviors' , ( ) => {
615+ let originalLocation : PropertyDescriptor | undefined ;
616+
617+ beforeEach ( ( ) => {
618+ originalLocation = Object . getOwnPropertyDescriptor ( window , 'location' ) ;
619+ } ) ;
620+
621+ afterEach ( ( ) => {
622+ if ( originalLocation ) {
623+ Object . defineProperty ( window , 'location' , originalLocation ) ;
624+ }
625+ } ) ;
626+
621627 test ( 'window reload is called when the refresh action is clicked' , ( ) => {
628+ const mockReload = jest . fn ( ) ;
629+ Object . defineProperty ( window , 'location' , { configurable : true , value : { reload : mockReload } } ) ;
630+
622631 renderWithErrorBoundary ( < b > { { } } </ b > ) ;
623632 findRefreshAction ( ) ! . click ( ) ;
624- expect ( refreshPage ) . toHaveBeenCalledTimes ( 1 ) ;
633+ expect ( mockReload ) . toHaveBeenCalledTimes ( 1 ) ;
634+ } ) ;
635+
636+ test ( 'hides default refresh in cross-origin iframes' , ( ) => {
637+ Object . defineProperty ( window , 'location' , {
638+ configurable : true ,
639+ value : {
640+ get href ( ) {
641+ throw new Error ( ) ;
642+ } ,
643+ } ,
644+ } ) ;
645+
646+ renderWithErrorBoundary ( < b > { { } } </ b > ) ;
647+ expect ( findRefreshAction ( ) ) . toBe ( null ) ;
625648 } ) ;
626649} ) ;
627650
0 commit comments