debian-mirror-gitlab/spec/frontend/ci/runner/sentry_utils_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-09-30 23:02:18 +05:30
import * as Sentry from '@sentry/browser';
2023-01-13 00:05:48 +05:30
import { captureException } from '~/ci/runner/sentry_utils';
2021-09-30 23:02:18 +05:30
jest.mock('@sentry/browser');
2023-01-13 00:05:48 +05:30
describe('~/ci/runner/sentry_utils', () => {
2021-09-30 23:02:18 +05:30
let mockSetTag;
beforeEach(async () => {
mockSetTag = jest.fn();
Sentry.withScope.mockImplementation((fn) => {
const scope = { setTag: mockSetTag };
fn(scope);
});
});
describe('captureException', () => {
const mockError = new Error('Something went wrong!');
it('error is reported to sentry', () => {
captureException({ error: mockError });
expect(Sentry.withScope).toHaveBeenCalled();
expect(Sentry.captureException).toHaveBeenCalledWith(mockError);
});
it('error is reported to sentry with a component name', () => {
const mockComponentName = 'MyComponent';
captureException({ error: mockError, component: mockComponentName });
expect(Sentry.withScope).toHaveBeenCalled();
expect(Sentry.captureException).toHaveBeenCalledWith(mockError);
expect(mockSetTag).toHaveBeenCalledWith('vue_component', mockComponentName);
});
});
});