Skip to content
Snippets Groups Projects
Commit d82e709f authored by Winnie Hellmann's avatar Winnie Hellmann
Browse files

Make sure that axios adapater is restored after mocking

parent dcb79741
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -22,3 +22,11 @@ axios.interceptors.response.use((config) => {
});
 
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;
Loading
Loading
@@ -6,6 +6,8 @@ import '~/commons';
import Vue from 'vue';
import VueResource from 'vue-resource';
 
import { getDefaultAdapter } from '~/lib/utils/axios_utils';
const isHeadlessChrome = /\bHeadlessChrome\//.test(navigator.userAgent);
Vue.config.devtools = !isHeadlessChrome;
Vue.config.productionTip = false;
Loading
Loading
@@ -59,6 +61,8 @@ beforeEach(() => {
Vue.http.interceptors = builtinVueHttpInterceptors.slice();
});
 
const axiosDefaultAdapter = getDefaultAdapter();
// render all of our tests
const testsContext = require.context('.', true, /_spec$/);
testsContext.keys().forEach(function (path) {
Loading
Loading
@@ -94,6 +98,12 @@ describe('test errors', () => {
it('has no Vue error', () => {
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
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment