[Vuejs]-Unable to properly mock API calls using Jest

0👍

It depends on how you set the global this.$api, but if you want to mock an entire file (especially using the default export), you should use the __esModule property:

jest.mock('./esModule', () => ({
  __esModule: true, // this property makes it work
  default: 'mockedDefaultExport',
  namedExport: jest.fn(),
}));

More explanations on Jest mock default and named export.

Leave a comment