Adding tests for RavenError

This commit is contained in:
Jeff Avallone 2018-02-11 11:57:23 -05:00
parent 5f11a11ba2
commit 7caf439c53
2 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,47 @@
import React from 'react';
import { shallow } from 'enzyme';
jest.mock('../sentry');
import RavenError from './RavenError';
import { Raven } from '../sentry';
const testError = { error: 'test error' };
const testDetails = { details: 'test details' };
describe('RavenError', () => {
test('rendering', () => {
const component = shallow(
<RavenError
error={ testError }
details={ testDetails }
heading="Test error"/>
);
expect(component).toMatchSnapshot();
});
test('captures exception', () => {
shallow(
<RavenError
error={ testError }
details={ testDetails }
heading="Test error"/>
);
expect(Raven.captureException).toHaveBeenCalledWith(testError, testDetails);
});
test('error reporting', () => {
Raven.lastEventId.mockReturnValue(1);
const component = shallow(
<RavenError
error={ testError }
details={ testDetails }
heading="Test error"/>
);
const eventObj = { preventDefault: jest.fn() };
component.find('a').simulate('click', eventObj);
expect(eventObj.preventDefault).toHaveBeenCalled();
expect(Raven.showReportDialog).toHaveBeenCalled();
});
});

View File

@ -0,0 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`RavenError rendering 1`] = `
<Message
heading="Test error"
icon={[Function]}
>
<p>
This error has been logged. You may also
<a
href="#error-report"
onClick={[Function]}
>
fill out a report
</a>
.
</p>
</Message>
`;