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 | |
parent | 663b7bb4771f3261d7451b6e1d74c778fd0e3589 (diff) |
Fix test false passes on unmocked requests
Diffstat (limited to 'spec/frontend/mocks')
-rw-r--r-- | spec/frontend/mocks/ce/lib/utils/axios_utils.js | 3 | ||||
-rw-r--r-- | spec/frontend/mocks/mocks_helper_spec.js | 7 | ||||
-rw-r--r-- | spec/frontend/mocks/node/jquery.js | 4 |
3 files changed, 8 insertions, 6 deletions
diff --git a/spec/frontend/mocks/ce/lib/utils/axios_utils.js b/spec/frontend/mocks/ce/lib/utils/axios_utils.js index b4065626b09..a3783b91f95 100644 --- a/spec/frontend/mocks/ce/lib/utils/axios_utils.js +++ b/spec/frontend/mocks/ce/lib/utils/axios_utils.js @@ -6,9 +6,10 @@ axios.isMock = true; axios.defaults.adapter = config => { const message = `Unexpected unmocked request: ${JSON.stringify(config, null, 2)}\n` + - 'Consider using the `axios-mock-adapter` in tests.'; + 'Consider using the `axios-mock-adapter` module in tests.'; const error = new Error(message); error.config = config; + global.fail(error); throw error; }; diff --git a/spec/frontend/mocks/mocks_helper_spec.js b/spec/frontend/mocks/mocks_helper_spec.js index b8bb02c2f43..82e88b712c0 100644 --- a/spec/frontend/mocks/mocks_helper_spec.js +++ b/spec/frontend/mocks/mocks_helper_spec.js @@ -1,4 +1,4 @@ -/* eslint-disable global-require, promise/catch-or-return */ +/* eslint-disable global-require */ import path from 'path'; @@ -126,9 +126,8 @@ describe('mocks_helper.js', () => { it('survives jest.isolateModules()', done => { jest.isolateModules(() => { const axios2 = require('~/lib/utils/axios_utils').default; - expect(axios2.get('http://gitlab.com')) - .rejects.toThrow('Unexpected unmocked request') - .then(done); + expect(axios2.isMock).toBe(true); + done(); }); }); diff --git a/spec/frontend/mocks/node/jquery.js b/spec/frontend/mocks/node/jquery.js index 34a25772f67..5c82f65406e 100644 --- a/spec/frontend/mocks/node/jquery.js +++ b/spec/frontend/mocks/node/jquery.js @@ -4,9 +4,11 @@ const $ = jest.requireActual('jquery'); // Fail tests for unmocked requests $.ajax = () => { - throw new Error( + const err = new Error( 'Unexpected unmocked jQuery.ajax() call! Make sure to mock jQuery.ajax() in tests.', ); + global.fail(err); + throw err; }; // jquery is not an ES6 module |