scratch-www/test/unit/components/errorboundary.test.jsx

25 lines
1 KiB
React
Raw Normal View History

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