From e8d2c2579383897a1dd7f9debd359abe8ae8373d Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 20 Jul 2021 09:55:51 +0000 Subject: Add latest changes from gitlab-org/gitlab@14-1-stable-ee --- spec/frontend/runner/sentry_utils_spec.js | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 spec/frontend/runner/sentry_utils_spec.js (limited to 'spec/frontend/runner/sentry_utils_spec.js') diff --git a/spec/frontend/runner/sentry_utils_spec.js b/spec/frontend/runner/sentry_utils_spec.js new file mode 100644 index 00000000000..b61eb63961e --- /dev/null +++ b/spec/frontend/runner/sentry_utils_spec.js @@ -0,0 +1,39 @@ +import * as Sentry from '@sentry/browser'; +import { captureException } from '~/runner/sentry_utils'; + +jest.mock('@sentry/browser'); + +describe('~/runner/sentry_utils', () => { + 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); + }); + }); +}); -- cgit v1.2.1