Fail tests for unmocked axios requests

This commit is contained in:
Winnie Hellmann 2019-02-20 20:59:44 +01:00
parent 69f9ec77c2
commit 13bb3483d8

View file

@ -1,3 +1,5 @@
import axios from '~/lib/utils/axios_utils';
const testTimeoutInMs = 300;
jest.setTimeout(testTimeoutInMs);
@ -14,3 +16,15 @@ afterEach(() => {
throw new Error(`Test took too long (${elapsedTimeInMs}ms > ${testTimeoutInMs}ms)!`);
}
});
// fail tests for unmocked requests
beforeEach(done => {
axios.defaults.adapter = config => {
const error = new Error(`Unexpected unmocked request: ${JSON.stringify(config, null, 2)}`);
error.config = config;
done.fail(error);
return Promise.reject(error);
};
done();
});