File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,6 +30,23 @@ describe('User Model', () => {
3030 expect ( typeof result ) . toBe ( 'number' ) ;
3131 expect ( Number . isFinite ( result ) ) . toBe ( true ) ;
3232 } ) ;
33+
34+ it ( 'has a defined defaultValue that is Date.now or returns a Date' , ( ) => {
35+ const createdAtPath = User . schema . path ( 'createdAt' ) as mongoose . SchemaType & {
36+ defaultValue ?: unknown ;
37+ options : { default ?: unknown } ;
38+ } ;
39+
40+ const defaultValue = createdAtPath . defaultValue ?? createdAtPath . options . default ;
41+
42+ expect ( defaultValue ) . toBeDefined ( ) ;
43+
44+ if ( defaultValue !== Date . now ) {
45+ expect ( typeof defaultValue ) . toBe ( 'function' ) ;
46+ const value = ( defaultValue as ( ) => unknown ) ( ) ;
47+ expect ( value instanceof Date ) . toBe ( true ) ;
48+ }
49+ } ) ;
3350 } ) ;
3451 it ( 'has trim: true on username path' , ( ) => {
3552 const usernamePath = User . schema . path ( 'username' ) as mongoose . SchemaType & {
You can’t perform that action at this time.
0 commit comments