I am creating a TypeScript interface for each model that extends mongoose.Document.
import mongoose, { Document } from 'mongoose';
export interface IAccount extends Document {
_id: mongoose.Types.ObjectId;
name: string;
industry: string;
}
The schema is then exported with the interface:
export default mongoose.model<IAccount>('Account', accountSchema);
The problem is that in Jest, creating an object with the properties required for the function being testing isn't enough, TypeScript complains about all the missing fields.
function getData(account: IAccount){
return account;
}
const account = {
name: 'Test account name',
industry: 'test account industry'
}
getData(account);
Argument of type '{ name: string; industry: string; }' is not assignable to parameter of type 'IAccount'. Type '{ name: string; industry: string; }' is missing the following properties from type 'IAccount': _id, increment, model, and 52 more.ts(2345)
What is the simplest way to create an object that satisfies TypeScript for testing purposes?