【发布时间】:2019-12-20 21:18:08
【问题描述】:
我正在尝试在我的 nestjs 应用程序中模拟一个 mongoose 文档,然后在我的单元测试中使用它。
fund.mock.ts
import { Fund } from '../interfaces/fund.interface';
export const FundMock: Fund = {
isin: 'FR0000000000',
name: 'Test',
currency: 'EUR',
fund_type: 'uc',
company: '5cf6697eecb759de13fc2c73',
fed: true,
};
fund.interface.ts
import { Document } from 'mongoose';
export interface Fund extends Document {
isin: string;
name: string;
fed: boolean;
currency: string;
fund_type: string;
company: string;
}
从逻辑上讲,它会输出一个错误,指出缺少文档属性。
is missing the following properties from type 'Fund': increment, model, $isDeleted, remove, and 53 more.
在我的测试中,我像这样模拟 getFund() 方法:
service.getFund = async () => FundMock;
getFund 期望返回 Promise<Fund>
那么我该如何模拟这些属性呢?
【问题讨论】:
标签: mongodb typescript unit-testing mongoose nestjs