Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
Vue jest probando acciones vuex

Estoy tratando de probar algunas acciones de vista que son promesas. He probado con éxito que las promesas se resuelven, ahora estoy tratando de probar los rechazos de promesas, el código en mis componentes se ve así:

 mounted() { this.GET_WORKFLOW_TYPES() .then(() => { this.GET_WORKFLOW_EVENTS_BY_TYPE({ workflow_type: this.selectedWorkflow, }) .then(() => { this.loading = false; }) .catch((error) => { console.log("2 " + error); this.loading = false; this.error = error }); }) .catch((error) => { console.log("1 " + error); this.loading = false; this.error = error }); },

Mi prueba se ve así, básicamente estoy tratando de probar que el código cae en la catch

 test('It should show an error if the mounted vuex action failed', async() => { actions = { GET_WORKFLOW_TYPES: jest.fn(() => { Promise.reject(new Error("Problem encountered 1")) }), GET_WORKFLOW_EVENTS_BY_TYPE: jest.fn(() => { Promise.reject(new Error("Problem encountered 2")) }), }; store = new Vuex.Store({ modules: { audit: { actions, mutations, state } } }); wrapper = shallowMount(AdminAudit, { store, localVue }); await wrapper.vm.$nextTick() expect(actions.GET_WORKFLOW_TYPES).rejects.toBe(true); await wrapper.vm.$nextTick(); expect(wrapper.vm.loading).toBe(false); });

Entonces, estoy probando que el rechazo es verdadero y que luego restablece algunos de los datos del componente ( loading:false ).

Sin embargo, me sale este error,

 expect(received).rejects.toEqual() Matcher error: received value must be a promise Received has type: function Received has value: [Function mockConstructor] 77 | wrapper = shallowMount(AdminAudit, { store, localVue }); 78 | await wrapper.vm.$nextTick() > 79 | expect(actions.GET_WORKFLOW_TYPES).rejects.toEqual(new Error("Problem encountered 1")); | ^ 80 | await wrapper.vm.$nextTick(); 81 | expect(wrapper.vm.loading).toBe(false); 82 | });

¿Cómo haría para probar una acción vuex que devuelve una promesa, supongo que lo estoy haciendo de manera incorrecta?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!