summaryrefslogtreecommitdiff
path: root/spec/frontend/mocks_spec.js
blob: a4a1fdea3964ad534d033d166806a7dc7509e1fb (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
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', done => {
      expect(axios.get('http://gitlab.com')).rejects.toThrow('Unexpected unmocked request');
      setImmediate(() => {
        expect(failMock).toHaveBeenCalledTimes(1);
        done();
      });
    });

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