Commit ab6f4ad4 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'winh-check-axios-restore' into 'master'

Make sure that axios adapater is restored after mocking

See merge request gitlab-org/gitlab-ce!16660
parents b8d044af d82e709f
...@@ -22,3 +22,11 @@ axios.interceptors.response.use((config) => { ...@@ -22,3 +22,11 @@ axios.interceptors.response.use((config) => {
}); });
export default axios; export default axios;
/**
* @return The adapter that axios uses for dispatching requests. This may be overwritten in tests.
*
* @see https://github.com/axios/axios/tree/master/lib/adapters
* @see https://github.com/ctimmerm/axios-mock-adapter/blob/v1.12.0/src/index.js#L39
*/
export const getDefaultAdapter = () => axios.defaults.adapter;
...@@ -6,6 +6,8 @@ import '~/commons'; ...@@ -6,6 +6,8 @@ import '~/commons';
import Vue from 'vue'; import Vue from 'vue';
import VueResource from 'vue-resource'; import VueResource from 'vue-resource';
import { getDefaultAdapter } from '~/lib/utils/axios_utils';
const isHeadlessChrome = /\bHeadlessChrome\//.test(navigator.userAgent); const isHeadlessChrome = /\bHeadlessChrome\//.test(navigator.userAgent);
Vue.config.devtools = !isHeadlessChrome; Vue.config.devtools = !isHeadlessChrome;
Vue.config.productionTip = false; Vue.config.productionTip = false;
...@@ -59,6 +61,8 @@ beforeEach(() => { ...@@ -59,6 +61,8 @@ beforeEach(() => {
Vue.http.interceptors = builtinVueHttpInterceptors.slice(); Vue.http.interceptors = builtinVueHttpInterceptors.slice();
}); });
const axiosDefaultAdapter = getDefaultAdapter();
// render all of our tests // render all of our tests
const testsContext = require.context('.', true, /_spec$/); const testsContext = require.context('.', true, /_spec$/);
testsContext.keys().forEach(function (path) { testsContext.keys().forEach(function (path) {
...@@ -94,6 +98,12 @@ describe('test errors', () => { ...@@ -94,6 +98,12 @@ describe('test errors', () => {
it('has no Vue error', () => { it('has no Vue error', () => {
expect(hasVueErrors).toBe(false); expect(hasVueErrors).toBe(false);
}); });
it('restores axios adapter after mocking', () => {
if (getDefaultAdapter() !== axiosDefaultAdapter) {
fail('axios adapter is not restored! Did you forget a restore() on MockAdapter?');
}
});
}); });
// if we're generating coverage reports, make sure to include all files so // if we're generating coverage reports, make sure to include all files so
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment