Skip to content

Instantly share code, notes, and snippets.

@nickytonline
Last active October 29, 2017 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickytonline/637580f12f14595f7954ecdaf5c8cd88 to your computer and use it in GitHub Desktop.
Save nickytonline/637580f12f14595f7954ecdaf5c8cd88 to your computer and use it in GitHub Desktop.
import test from 'ava';
import React from 'react';
import { shallow } from 'enzyme';
import CaptureError from '../CaptureError';
const render = ({
ComponentToWrap,
ErrorComponent,
environment = 'development',
}) => {
const ErrorBoundaryComponent = CaptureError({
ComponentToWrap,
ErrorComponent,
environment,
});
return shallow(<ErrorBoundaryComponent />);
};
const DummyComponent = () => <div>hello world</div>;
const FriendlyError = () => <div>oh no!</div>;
const ErroredComponent = () => {
throw new Error('Oh no!');
};
test('Should render the component to wrap if there are no errors.', t => {
const wrapper = render({
ComponentToWrap: DummyComponent,
ErrorComponent: FriendlyError,
});
t.true(wrapper.equals(<DummyComponent />));
});
// TODO: Get this skipped test working. The HOC works properly but I'm having issues testing the rendering
// when cDC is at play. At the moment, wrapper.html() simply returns the text Error: 'oh no!' which corresponds
// to the error thrown by <ErroredComponent />.
// I've subscribed to https://github.com/airbnb/enzyme/issues/1255 which seems to be related, but no answers there
// yet.
test.skip(
'Should render the <FriendlyError /> component if the environment is production and there are errors.',
t => {
const wrapper = render({
ComponentToWrap: ErroredComponent,
ErrorComponent: FriendlyError,
environment: 'production',
});
t.true(wrapper.equals(<FriendlyError />));
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment