scratch-www/test/unit/components/errorboundary.test.jsx
2023-01-27 06:57:29 -08:00

24 lines
1 KiB
JavaScript

import React from 'react';
const {mountWithIntl} = require('../../helpers/intl-helpers.jsx');
import CrashMessageComponent from '../../../src/components/crashmessage/crashmessage.jsx';
import ErrorBoundary from '../../../src/components/errorboundary/errorboundary.jsx';
const ChildComponent = () => <div>hello</div>;
describe('ErrorBoundary', () => {
test('ErrorBoundary shows children before error and CrashMessageComponent after', () => {
const child = <ChildComponent />;
const wrapper = mountWithIntl(<ErrorBoundary>{child}</ErrorBoundary>);
const childWrapper = wrapper.childAt(0);
expect(wrapper.containsMatchingElement(child)).toBeTruthy();
expect(wrapper.containsMatchingElement(<CrashMessageComponent />)).toBeFalsy();
childWrapper.simulateError(new Error('fake error for testing purposes'));
expect(wrapper.containsMatchingElement(child)).toBeFalsy();
expect(wrapper.containsMatchingElement(<CrashMessageComponent />)).toBeTruthy();
});
});