import * as service from '../../../src/common/models/request'; import * as WEDA_CLOUD_SDK from '@cloudbase/weda-cloud-sdk'; describe('test src/mp/common/service.ts', () => { beforeEach(() => { // restore the spy created with spyOn jest.restoreAllMocks(); }); it('test callWedaApiFn has Data', async () => { const result = { Data: [] }; jest.spyOn(service, 'callWedaApiFn').mockImplementationOnce(async () => result); const res = await service.callWedaApiFn('action', {}); expect(res).toMatchObject(result); }); it('test callWedaApiFn has not Data', async () => { try { jest.spyOn(WEDA_CLOUD_SDK.CLOUD_SDK, 'callWedaApi').mockImplementationOnce(async () => undefined); const res = await service.callWedaApiFn('action'); expect(res).toBeUndefined(); } catch (err) {} }); });