我是Jest和React的新手。有一个带有https-service.ts文件的服务文件夹。代码从下面开始:
import { IFlowEvent } from '@abc/mca-api-flow';
import { ApiMCA } from '@abc/mca-api-mca';
import { IServiceRequest } from '@abc/mca-api-service';
export class HttpService {
private static api: ApiMCA;
public static intialize(api: ApiMCA, callbackFn: Function) {
HttpService.api = api;
callbackFn();
}
public static dispatchAction<T>(
serviceId: string, request?: IServiceRequest): Promise<{ data: T }> {
return HttpService.api.service
.call(serviceId, request)
.then(({ data }) => data as { data: T });
}
public static dispatchFlow(payload: IFlowEvent) {
return HttpService.api.flow.dispatch(payload);
}
public static get communication() {
return this.api.communication;
}
}
我想模拟上面的代码,并在我的测试用例中在beforeEach中使用。