考虑到下面的这个比较繁琐的类获取Elasticsearch(或者其他数据存储方式)中的单个记录:
export default class UserRepoImpl implements UserRepo {
constructor(private readonly esClient: ElasticsearchClient) {}
public async getUser(id: string): Promise<User> {
const response = await this.esClient.request('GET', `/users/_doc/${id}`);
return response._source;
}
}
我该如何编写一个测试,以便为我实例化一个
UserRepoImpl
,但在构造函数的参数中插入一个mocked ElasticsearchClient?
await expect
。 - Estus FlaskType '{ request: Mock<any, any>; }' is not assignable to type 'Mocked<ElasticsearchClient>'. Type '{ request: Mock<any, any>; }' is missing the following properties from type 'ElasticsearchClient': awsHttps, endpoint
。 - Jeffrey Wen