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

cache_updates_spec.js « boards « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 07f5cef4a362a4f23a0a40af56688b592dd026ff (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
import * as Sentry from '~/sentry/sentry_browser_wrapper';
import { setError } from '~/boards/graphql/cache_updates';
import { defaultClient } from '~/graphql_shared/issuable_client';
import setErrorMutation from '~/boards/graphql/client/set_error.mutation.graphql';

describe('setError', () => {
  let sentryCaptureExceptionSpy;
  const errorMessage = 'Error';
  const error = new Error(errorMessage);

  beforeEach(() => {
    jest.spyOn(defaultClient, 'mutate').mockResolvedValue();
    sentryCaptureExceptionSpy = jest.spyOn(Sentry, 'captureException');
  });

  it('calls setErrorMutation and capture Sentry error', () => {
    setError({ message: errorMessage, error });

    expect(defaultClient.mutate).toHaveBeenCalledWith({
      mutation: setErrorMutation,
      variables: { error: errorMessage },
    });

    expect(sentryCaptureExceptionSpy).toHaveBeenCalledWith(error);
  });

  it('does not capture Sentry error when captureError is false', () => {
    setError({ message: errorMessage, error, captureError: false });

    expect(defaultClient.mutate).toHaveBeenCalledWith({
      mutation: setErrorMutation,
      variables: { error: errorMessage },
    });

    expect(sentryCaptureExceptionSpy).not.toHaveBeenCalled();
  });
});