[Vuejs]-Unit test with Jest and Sinon in a Nuxt application

0👍

You need to define axios stub when you do shallowMount.

For example:

const data = { data: { items: [{ id: 1 }, { id: 2 }] } }
return shallowMount(BarChart, {
  stubs: {
    highcharts: true,
  },
  mocks: { 
    $axios: jest.fn(() => Promise.resolve(data)),
  },  
});

You do not need to use sinon, @vue/test-utils and jest have provided way to mock axios.

Leave a comment