Is there a preferred way to mock deeply-nested types when testing TypeScript apps?
I'm using the @types/aws-lambda
package, and it has lots of types like this:
export interface S3EventRecord {
eventVersion: string;
eventSource: string;
awsRegion: string;
eventTime: string;
eventName: string;
userIdentity: {
principalId: string;
};
requestParameters: {
sourceIPAddress: string;
};
responseElements: {
'x-amz-request-id': string;
'x-amz-id-2': string;
};
s3: {
s3SchemaVersion: string;
configurationId: string;
bucket: {
name: string;
ownerIdentity: {
principalId: string;
};
arn: string;
};
object: {
key: string;
size: number;
eTag: string;
versionId?: string | undefined;
sequencer: string;
};
};
glacierEventData?: S3EventRecordGlacierEventData | undefined;
}
Naturally, I don't care about a lot of these properties during my unit tests, and would like to mock them out with dummy data in an easy way.
I've looked around but can't seem to find any libraries for my purpose.
I have played around with the Partial<Type>
, but it doesn't seem to suit my purpose due to this S3EventRecord
being held as an array in yet another type.