Adding tests for RavenError
This commit is contained in:
parent
5f11a11ba2
commit
7caf439c53
47
src/components/RavenError.test.js
Normal file
47
src/components/RavenError.test.js
Normal 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();
|
||||
});
|
||||
});
|
19
src/components/__snapshots__/RavenError.test.js.snap
Normal file
19
src/components/__snapshots__/RavenError.test.js.snap
Normal 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>
|
||||
`;
|
Loading…
Reference in New Issue
Block a user