I am currently in the process of mocking an ES6 class that is being utilized within my Vue Component:
export default class DataUploadApi {
// Get uploaded files
static async getUploadedFiles() : Promise<Object> {
return WebapiBase.getAsync({uri: DATA_UPLOAD_ENPOINTS.FILES});
}
}
In my attempt to follow this guide, I believe there may be a syntax issue with my mock implementation:
import { mount } from '@vue/test-utils';
import DataUploadApi from '../webapi/DataUploadService';
import FileDownloadList from '../components/file-download-list.vue';
const mockGetUploadedFiles = jest.fn().mockResolvedValue({json: JSON.stringify(uploadedFilesObj)});
jest.mock('../webapi/DataUploadService', () => jest.fn().mockImplementation(() => ({getUploadedFiles: mockGetUploadedFiles})));
describe('file-download-list component', () => {
beforeEach(() => {
// @ts-ignore
DataUploadApi.mockClear();
mockGetUploadedFiles.mockClear();
});
describe('renders correct markup:', () => {
it('without any uploaded files', () => {
const wrapper = mount(FileDownloadList, {});
expect(wrapper).toMatchSnapshot();
});
});
});
While this test passes, upon inspecting the snapshot, I discovered that the API call failed and displayed the following error message:
<p>
_DataUploadService.default.getUploadedFiles is not a function
</p>
Could someone kindly point out what might be wrong with my function mock? Thank you for your assistance!