Commit d97352fd authored by Miguel Rincon's avatar Miguel Rincon

Add tests to capture errors using flash

This change adds tests to the `~/flash` util to confirm errors
are reported to Sentry.
parent c32ce41e
import * as Sentry from '@sentry/browser';
import createFlash, {
hideFlash,
addDismissFlashClickListener,
......@@ -5,6 +6,8 @@ import createFlash, {
FLASH_CLOSED_EVENT,
} from '~/flash';
jest.mock('@sentry/browser');
describe('Flash', () => {
describe('hideFlash', () => {
let el;
......@@ -150,6 +153,23 @@ describe('Flash', () => {
expect(document.body.className).not.toContain('flash-shown');
});
it('does not capture error using Sentry', () => {
createFlash({ ...defaultParams, captureError: false, error: new Error('Error!') });
expect(Sentry.captureException).not.toHaveBeenCalled();
});
it('captures error using Sentry', () => {
createFlash({ ...defaultParams, captureError: true, error: new Error('Error!') });
expect(Sentry.captureException).toHaveBeenCalledWith(expect.any(Error));
expect(Sentry.captureException).toHaveBeenCalledWith(
expect.objectContaining({
message: 'Error!',
}),
);
});
describe('with actionConfig', () => {
const findFlashAction = () => document.querySelector('.flash-container .flash-action');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment