Estoy usando Jest con vuejs 2.
Cuando ejecuto la prueba por separado, tiene éxito, pero cuando ejecuto pruebas en todo el archivo, falla.
Probé todas las soluciones propuestas para clearMocks y resetMocks ect, pero no funcionó conmigo.
El proyecto está disponible en github .
Aquí está mi código:
// views/analytics.ts import { getAnalytics } from '@/client/analytics'; // this method returns a Promise export default Vue.extend({ ... data() { return { property1: '', } }, mounted() { getAnalytics(this.agentName, size).then((response) => { this.property1 = response.propertyName }) } }) // client/analytics.ts const getAnalytics = async (agentName: string, size: number): Promise<any> => { const response = await axios.get(url, opt); _.reverse((response as any).analytics); return response; }; export { getAnalytics, }; // analytics.spec.ts jest.mock('@/client/analytics', () => ({ getAnalytics: () => Promise.resolve(mockedData), // mockedData is a JSON object })); describe ('analytics.vue', () => { beforeEach(async () => { jest.resetModules(); jest.clearAllMocks(); const localVue = createLocalVue(); localVue.use(ElementUI); wrapper = shallowMount(Analytics, { localVue, mocks: { $route, }, }); comp = wrapper.vm; }); afterEach(() => { wrapper.destroy(); }); it('test 1', async () => { const myProperty = comp.$data.property1; expect(myProperty).toEqual('expectedValue'); }) it('test 2', async () => { // same body as test 1. }) })Probé diferentes proposiciones de aquí y aquí pero no funciona conmigo.