Skip to content

Commit

Permalink
build: suppress logs from intentionally thrown/caught errors (apache#221
Browse files Browse the repository at this point in the history
)
  • Loading branch information
kristw authored and zhaoyongjie committed Nov 24, 2021
1 parent a431fd6 commit c7eb66f
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,27 @@ describe('SuperChart', () => {
});

describe('includes ErrorBoundary', () => {
let expectedErrors = 0;
let actualErrors = 0;
function onError(e) {
e.preventDefault();
actualErrors += 1;
}

beforeEach(() => {
expectedErrors = 0;
actualErrors = 0;
window.addEventListener('error', onError);
});

afterEach(() => {
window.removeEventListener('error', onError);
expect(actualErrors).toBe(expectedErrors);
expectedErrors = 0;
});

it('renders default FallbackComponent', () => {
expectedErrors = 1;
jest.spyOn(RealSuperChart.defaultProps, 'FallbackComponent');
const wrapper = mount(<SuperChart chartType={ChartKeys.BUGGY} width="200" height="200" />);
const renderedWrapper = wrapper.render();
Expand All @@ -45,6 +65,7 @@ describe('SuperChart', () => {
}, 100);
});
it('renders custom FallbackComponent', () => {
expectedErrors = 1;
const CustomFallbackComponent = jest.fn(() => <div>Custom Fallback!</div>);
const wrapper = mount(
<SuperChart
Expand All @@ -61,6 +82,7 @@ describe('SuperChart', () => {
});
});
it('call onErrorBoundary', () => {
expectedErrors = 1;
const handleError = jest.fn();
mount(
<SuperChart
Expand All @@ -76,6 +98,7 @@ describe('SuperChart', () => {
});
});
it('does not include ErrorBoundary if told so', () => {
expectedErrors = 1;
const inactiveErrorHandler = jest.fn();
const activeErrorHandler = jest.fn();
mount(
Expand Down

0 comments on commit c7eb66f

Please sign in to comment.