summaryrefslogtreecommitdiff
path: root/spec/frontend/mocks_spec.js
blob: 110c418e57962603a6998f7cea080aff66024335 (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
import $ from 'jquery';
import axios from '~/lib/utils/axios_utils';

describe('Mock auto-injection', () => {
  describe('mocks', () => {
    let failMock;
    beforeEach(() => {
      failMock = jest.spyOn(global, 'fail').mockImplementation();
    });

    it('~/lib/utils/axios_utils', () => {
      return Promise.all([
        expect(axios.get('http://gitlab.com')).rejects.toThrow('Unexpected unmocked request'),
        setImmediate(() => {
          expect(failMock).toHaveBeenCalledTimes(1);
        }),
      ]);
    });

    it('jQuery.ajax()', () => {
      expect($.ajax).toThrow('Unexpected unmocked');
      expect(failMock).toHaveBeenCalledTimes(1);
    });
  });
});