-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee5398a
commit 32671b5
Showing
3 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
packages/customize-widgets/src/components/test/error-boundary.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import * as wpHooks from '@wordpress/hooks'; | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import ErrorBoundary from '../error-boundary'; | ||
/** | ||
* External dependencies | ||
*/ | ||
import { render } from '@testing-library/react'; | ||
|
||
const theError = new Error( 'Kaboom' ); | ||
|
||
const ChildComponent = () => { | ||
throw theError; | ||
}; | ||
|
||
describe( 'Error Boundary', () => { | ||
describe( 'when error is thrown from a Child component', () => { | ||
it( 'calls the `editor.ErrorBoundary.errorLogged` hook action with the error object', () => { | ||
const doAction = jest.spyOn( wpHooks, 'doAction' ); | ||
|
||
render( | ||
<ErrorBoundary> | ||
<ChildComponent /> | ||
</ErrorBoundary> | ||
); | ||
|
||
expect( doAction ).toHaveBeenCalledWith( | ||
'editor.ErrorBoundary.errorLogged', | ||
theError | ||
); | ||
expect( console ).toHaveErrored(); | ||
} ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import * as wpHooks from '@wordpress/hooks'; | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import ErrorBoundary from '../error-boundary'; | ||
/** | ||
* External dependencies | ||
*/ | ||
import { render } from '@testing-library/react'; | ||
|
||
const theError = new Error( 'Kaboom' ); | ||
|
||
const ChildComponent = () => { | ||
throw theError; | ||
}; | ||
|
||
describe( 'Error Boundary', () => { | ||
describe( 'when error is thrown from a Child component', () => { | ||
it( 'calls the `editor.ErrorBoundary.errorLogged` hook action with the error object', () => { | ||
const doAction = jest.spyOn( wpHooks, 'doAction' ); | ||
|
||
render( | ||
<ErrorBoundary> | ||
<ChildComponent /> | ||
</ErrorBoundary> | ||
); | ||
|
||
expect( doAction ).toHaveBeenCalledWith( | ||
'editor.ErrorBoundary.errorLogged', | ||
theError | ||
); | ||
expect( console ).toHaveErrored(); | ||
} ); | ||
} ); | ||
} ); |
38 changes: 38 additions & 0 deletions
38
packages/edit-widgets/src/components/test/error-boundary.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import * as wpHooks from '@wordpress/hooks'; | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import ErrorBoundary from '../error-boundary'; | ||
/** | ||
* External dependencies | ||
*/ | ||
import { render } from '@testing-library/react'; | ||
|
||
const theError = new Error( 'Kaboom' ); | ||
|
||
const ChildComponent = () => { | ||
throw theError; | ||
}; | ||
|
||
describe( 'Error Boundary', () => { | ||
describe( 'when error is thrown from a Child component', () => { | ||
it( 'calls the `editor.ErrorBoundary.errorLogged` hook action with the error object', () => { | ||
const doAction = jest.spyOn( wpHooks, 'doAction' ); | ||
|
||
render( | ||
<ErrorBoundary> | ||
<ChildComponent /> | ||
</ErrorBoundary> | ||
); | ||
|
||
expect( doAction ).toHaveBeenCalledWith( | ||
'editor.ErrorBoundary.errorLogged', | ||
theError | ||
); | ||
expect( console ).toHaveErrored(); | ||
} ); | ||
} ); | ||
} ); |