2019-09-30 21:07:59 +05:30
|
|
|
import $ from 'jquery';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
|
|
|
|
describe('Mock auto-injection', () => {
|
|
|
|
describe('mocks', () => {
|
2019-12-04 20:38:33 +05:30
|
|
|
let failMock;
|
|
|
|
beforeEach(() => {
|
|
|
|
failMock = jest.spyOn(global, 'fail').mockImplementation();
|
|
|
|
});
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it('~/lib/utils/axios_utils', () => {
|
|
|
|
return Promise.all([
|
|
|
|
expect(axios.get('http://gitlab.com')).rejects.toThrow('Unexpected unmocked request'),
|
|
|
|
setImmediate(() => {
|
|
|
|
expect(failMock).toHaveBeenCalledTimes(1);
|
|
|
|
}),
|
|
|
|
]);
|
2019-12-04 20:38:33 +05:30
|
|
|
});
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
it('jQuery.ajax()', () => {
|
|
|
|
expect($.ajax).toThrow('Unexpected unmocked');
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(failMock).toHaveBeenCalledTimes(1);
|
2019-09-30 21:07:59 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|