Closed sinner closed 1 year ago
Hey @sinner, may you provide the sample code you used to set up the mock? That way, we can find if anything is missing in your setup; if you could set up a codesandbox would be even easier to investigate o/
@antoniel Sure, this is pretty much the code. That component method loadAsyncData
uses axios to call the API, but in my tests I don't want to actually call the API. I expect the tests run even if the jenkins serve doesn't have internet connection.
import { shallowMount } from '@vue/test-utils';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import flushPromises from 'flush-promises';
import MockSecMktRules from '../__mocks__/SecMarketingRules.json';
const mock = new MockAdapter(axios);
describe('Component test', () => {
beforeEach(() => {
mock.restore();
mock
.onGet()
.reply(200, MockSecMktRules.success)
.onAny()
.reply(200, MockSecMktRules.success)
.passThrough();
});
test('behavior', async done => {
const wrapper = shallowMount(MockComponent);
await wrapper.vm.loadAsyncData();
});
});
I think this was caused by an axios v1 incompatibility. This should be fixed in newer versions.
I'm using the following version of the packages:
I followed the setting up instructions and this package actually does the requests to the API instead of mocking responses. It is causing several Network Errors in our deploying process because of that behavior.
This is a sample error when there is no internet conection: