【发布时间】:2020-11-03 20:12:14
【问题描述】:
您好,我尝试使用 jest 测试抽象类。但是,当尝试这样做时。我收到语法错误。我尝试使用 type: module 导入 cosmos 依赖项在 package.json 中添加 type:module 时出现此错误
import { Constants, CosmosClient, ErrorResponse, FeedOptions, FeedResponse, ItemResponse, SqlQuerySpec, StatusCodes } from '@azure/cosmos';
/**
* Abstract class with general CosmosDB utilities and wrappers.
*/
export abstract class AbstractCosmosService {
// TODO: Cannot be abstract yet: microsoft/TypeScript#34516
protected static CONNECTION_STRING: string;
protected static get dbClient(): CosmosClient {
return new CosmosClient(this.CONNECTION_STRING);
}
protected static recordRequestCharge(response: any): void {
if (typeof response === 'object' && response && response.hasOwnProperty('requestCharge')) {
// TODO: record request charge somehow
}
}
【问题讨论】:
-
您似乎没有将 Typescript 配置为与 Jest 一起使用(或相反)。
-
已配置。实际上很少有测试用例被执行。我只有抽象类的问题
-
不清楚为什么这是一个抽象类,但一般来说,如果您需要测试一个抽象类,您可以编写一个具体的测试实现并进行测试。
标签: javascript typescript unit-testing jestjs ts-jest