@@ -1122,6 +1122,36 @@ describe('model', () => {
11221122 expectType < Date > ( result . updatedAt ) ;
11231123 } ) ;
11241124
1125+ test ( 'timestamps schema with custom dates' , async ( ) => {
1126+ const date = new Date ( '2020-01-01T12:00:00' ) ;
1127+
1128+ const result = await timestampsModel . insertOne ( {
1129+ bar : 123 ,
1130+ createdAt : date ,
1131+ foo : 'foo' ,
1132+ updatedAt : date ,
1133+ } ) ;
1134+
1135+ expect ( collection . insertOne ) . toHaveBeenCalledWith (
1136+ {
1137+ bar : 123 ,
1138+ createdAt : date ,
1139+ foo : 'foo' ,
1140+ updatedAt : date ,
1141+ } ,
1142+ { ignoreUndefined : true }
1143+ ) ;
1144+
1145+ expectType < TimestampsDocument > ( result ) ;
1146+
1147+ expectType < ObjectId > ( result . _id ) ;
1148+ expectType < string > ( result . foo ) ;
1149+ expectType < number > ( result . bar ) ;
1150+ expectType < Date | undefined > ( result . ham ) ;
1151+ expectType < Date > ( result . createdAt ) ;
1152+ expectType < Date > ( result . updatedAt ) ;
1153+ } ) ;
1154+
11251155 test ( 'throws error on failure' , async ( ) => {
11261156 ( collection . insertOne as jest . Mock ) . mockResolvedValue ( { result : { ok : 0 } } ) ;
11271157
@@ -1219,15 +1249,29 @@ describe('model', () => {
12191249 } ) ;
12201250
12211251 test ( 'timestamps schema' , async ( ) => {
1252+ ( collection . insertMany as jest . Mock ) . mockResolvedValue ( {
1253+ acknowledged : true ,
1254+ insertedCount : 3 ,
1255+ insertedIds : [ new ObjectId ( ) , new ObjectId ( ) , new ObjectId ( ) ] ,
1256+ } ) ;
1257+
1258+ const date = new Date ( '2020-01-01T12:00:00' ) ;
12221259 const result = await timestampsModel . insertMany ( [
12231260 {
12241261 bar : 123 ,
12251262 foo : 'foo' ,
12261263 } ,
12271264 {
12281265 bar : 456 ,
1266+ createdAt : date ,
12291267 foo : 'bar' ,
12301268 } ,
1269+ {
1270+ bar : 789 ,
1271+ createdAt : date ,
1272+ foo : 'ham' ,
1273+ updatedAt : date ,
1274+ } ,
12311275 ] ) ;
12321276
12331277 expect ( collection . insertMany ) . toHaveBeenCalledWith (
@@ -1240,10 +1284,16 @@ describe('model', () => {
12401284 } ,
12411285 {
12421286 bar : 456 ,
1243- createdAt : expect . any ( Date ) ,
1287+ createdAt : date ,
12441288 foo : 'bar' ,
12451289 updatedAt : expect . any ( Date ) ,
12461290 } ,
1291+ {
1292+ bar : 789 ,
1293+ createdAt : date ,
1294+ foo : 'ham' ,
1295+ updatedAt : date ,
1296+ } ,
12471297 ] ,
12481298 { ignoreUndefined : true }
12491299 ) ;
0 commit comments