Adding Jest for testing

This commit is contained in:
Jeff Avallone
2019-01-04 18:38:49 -05:00
parent 6cff032efb
commit 8a3471b916
28 changed files with 5523 additions and 54 deletions
@@ -0,0 +1,149 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`SentryError rendering 1`] = `
ShallowWrapper {
Symbol(enzyme.__root__): [Circular],
Symbol(enzyme.__unrendered__): <SentryError />,
Symbol(enzyme.__renderer__): Object {
"batchedUpdates": [Function],
"getNode": [Function],
"render": [Function],
"simulateError": [Function],
"simulateEvent": [Function],
"unmount": [Function],
},
Symbol(enzyme.__node__): Object {
"instance": null,
"key": undefined,
"nodeType": "function",
"props": Object {
"children": <p>
This error has been logged. You may also
<a
href="#error-report"
onClick={[Function]}
>
fill out a report
</a>
.
</p>,
"heading": "An error has occurred",
"type": "error",
},
"ref": null,
"rendered": Object {
"instance": null,
"key": undefined,
"nodeType": "host",
"props": Object {
"children": Array [
"This error has been logged. You may also ",
<a
href="#error-report"
onClick={[Function]}
>
fill out a report
</a>,
".",
],
},
"ref": null,
"rendered": Array [
"This error has been logged. You may also ",
Object {
"instance": null,
"key": undefined,
"nodeType": "host",
"props": Object {
"children": "fill out a report",
"href": "#error-report",
"onClick": [Function],
},
"ref": null,
"rendered": "fill out a report",
"type": "a",
},
".",
],
"type": "p",
},
"type": [Function],
},
Symbol(enzyme.__nodes__): Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "function",
"props": Object {
"children": <p>
This error has been logged. You may also
<a
href="#error-report"
onClick={[Function]}
>
fill out a report
</a>
.
</p>,
"heading": "An error has occurred",
"type": "error",
},
"ref": null,
"rendered": Object {
"instance": null,
"key": undefined,
"nodeType": "host",
"props": Object {
"children": Array [
"This error has been logged. You may also ",
<a
href="#error-report"
onClick={[Function]}
>
fill out a report
</a>,
".",
],
},
"ref": null,
"rendered": Array [
"This error has been logged. You may also ",
Object {
"instance": null,
"key": undefined,
"nodeType": "host",
"props": Object {
"children": "fill out a report",
"href": "#error-report",
"onClick": [Function],
},
"ref": null,
"rendered": "fill out a report",
"type": "a",
},
".",
],
"type": "p",
},
"type": [Function],
},
],
Symbol(enzyme.__options__): Object {
"adapter": ReactSixteenAdapter {
"options": Object {
"enableComponentDidUpdateOnSetState": true,
"lifecycles": Object {
"componentDidUpdate": Object {
"onSetState": true,
},
"getDerivedStateFromProps": true,
"getSnapshotBeforeUpdate": true,
"setState": Object {
"skipsComponentDidUpdateOnNullish": true,
},
},
},
},
},
}
`;
+42
View File
@@ -0,0 +1,42 @@
jest.mock('@sentry/browser');
import React from 'react';
import { shallow } from 'enzyme';
import * as Sentry from '@sentry/browser';
import SentryError from 'components/SentryError';
describe('SentryError', () => {
test('rendering', () => {
const component = shallow(
<SentryError />
);
expect(component).toMatchSnapshot();
});
describe('error reporting', () => {
test('clicking to fill out a report when an event has been logged', () => {
Sentry.lastEventId.mockReturnValue(1);
const component = shallow(
<SentryError />
);
const eventObj = { preventDefault: jest.fn() };
component.find('a').simulate('click', eventObj);
expect(eventObj.preventDefault).toHaveBeenCalled();
expect(Sentry.showReportDialog).toHaveBeenCalled();
});
test('clicking to fill out a report when an event has not been logged', () => {
Sentry.lastEventId.mockReturnValue(false);
const component = shallow(
<SentryError />
);
const eventObj = { preventDefault: jest.fn() };
component.find('a').simulate('click', eventObj);
expect(eventObj.preventDefault).toHaveBeenCalled();
expect(Sentry.showReportDialog).not.toHaveBeenCalled();
});
});
});