summaryrefslogtreecommitdiff
path: root/spec/frontend/sentry/sentry_browser_wrapper_spec.js
blob: 55354eceb8d4fc3abd828e9e7a8fea94a5a25566 (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(() => {
      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);
    });
  });
});