diff options
author | Martin Hanzel <mhanzel@gitlab.com> | 2019-08-15 21:04:43 +0300 |
---|---|---|
committer | Martin Hanzel <mhanzel@gitlab.com> | 2019-08-30 21:29:02 +0300 |
commit | be6f20d54f1dd2de65ce477c644fd5819dedf9e9 (patch) | |
tree | 551f78e5924af01085a9f7fbde1515ade592d56c /spec/frontend/mocks_spec.js | |
parent | 663b7bb4771f3261d7451b6e1d74c778fd0e3589 (diff) |
Fix test false passes on unmocked requests
Diffstat (limited to 'spec/frontend/mocks_spec.js')
-rw-r--r-- | spec/frontend/mocks_spec.js | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/spec/frontend/mocks_spec.js b/spec/frontend/mocks_spec.js index 2d2324120fd..a4a1fdea396 100644 --- a/spec/frontend/mocks_spec.js +++ b/spec/frontend/mocks_spec.js @@ -3,11 +3,22 @@ import axios from '~/lib/utils/axios_utils'; describe('Mock auto-injection', () => { describe('mocks', () => { - it('~/lib/utils/axios_utils', () => - expect(axios.get('http://gitlab.com')).rejects.toThrow('Unexpected unmocked request')); + 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); }); }); }); |