用作猫鼬响应的对象应该是什么类型?
这是我的猫鼬模式/模式
import { model, Schema, Document } from "mongoose";
export interface ILocation extends Document{
name: string;
description: string;
}
const schema = new Schema({
name: { type: String, required: true },
description: { type: String, required: true },
});
export const Location = model<ILocation>(process.env.DB_CONTAINER || "Null", schema)
export default Location
然后我就有了一个create record方法,
const createRecord = async (
obj: ILocation,
model: IModel
): Promise<Response> => {
try {
const response = await model.create(obj);
return { code: 201, data: response };
} catch (error) {
return errorHandler(error);
}
};
这很好,一切正常,但是现在我需要模拟响应以进行uunit测试,并且我不能将任何对象作为假响应传递而没有TypeScript错误。
例如
const dummyRecord: ILocation = {
name: "name",
description: "description",
};
Location.create(dummyRecord);
// is missing the following properties increment, model and 54 more.ts
虚拟记录或模型的类型应该是什么,以便返回类型可以是我的模式?