Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fullofcaffeine committed Jul 8, 2022
1 parent ee5398a commit 32671b5
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
38 changes: 38 additions & 0 deletions packages/customize-widgets/src/components/test/error-boundary.js
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 packages/edit-site/src/components/test/error-boundary.js
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 packages/edit-widgets/src/components/test/error-boundary.js
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();
} );
} );
} );

0 comments on commit 32671b5

Please sign in to comment.