Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sentry_browser_wrapper_spec.js « sentry « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f4d646bab78e4dc3130115b74132402d803dbd16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import * as Sentry from '~/sentry/sentry_browser_wrapper';

const mockError = new Error('error!');
const mockMsg = 'msg!';
const mockFn = () => {};

describe('SentryBrowserWrapper', () => {
  afterEach(() => {
    // eslint-disable-next-line no-underscore-dangle
    delete window._Sentry;
  });

  describe('when _Sentry is not defined', () => {
    it('methods fail silently', () => {
      expect(() => {
        Sentry.captureException(mockError);
        Sentry.captureMessage(mockMsg);
        Sentry.withScope(mockFn);
      }).not.toThrow();
    });
  });

  describe('when _Sentry is defined', () => {
    let mockCaptureException;
    let mockCaptureMessage;
    let mockWithScope;

    beforeEach(async () => {
      mockCaptureException = jest.fn();
      mockCaptureMessage = jest.fn();
      mockWithScope = jest.fn();

      // eslint-disable-next-line no-underscore-dangle
      window._Sentry = {
        captureException: mockCaptureException,
        captureMessage: mockCaptureMessage,
        withScope: mockWithScope,
      };
    });

    it('captureException is called', () => {
      Sentry.captureException(mockError);

      expect(mockCaptureException).toHaveBeenCalledWith(mockError);
    });

    it('captureMessage is called', () => {
      Sentry.captureMessage(mockMsg);

      expect(mockCaptureMessage).toHaveBeenCalledWith(mockMsg);
    });

    it('withScope is called', () => {
      Sentry.withScope(mockFn);

      expect(mockWithScope).toHaveBeenCalledWith(mockFn);
    });
  });
});