File tree Expand file tree Collapse file tree
packages/jest-get-type/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,4 +23,5 @@ describe('.getType()', () => {
2323 test ( 'regexp' , ( ) => expect ( getType ( / a b c / ) ) . toBe ( 'regexp' ) ) ;
2424 test ( 'map' , ( ) => expect ( getType ( new Map ( ) ) ) . toBe ( 'map' ) ) ;
2525 test ( 'set' , ( ) => expect ( getType ( new Set ( ) ) ) . toBe ( 'set' ) ) ;
26+ test ( 'date' , ( ) => expect ( getType ( new Date ( ) ) ) . toBe ( 'date' ) ) ;
2627} ) ;
Original file line number Diff line number Diff line change @@ -19,14 +19,15 @@ export type ValueType =
1919 | 'regexp'
2020 | 'map'
2121 | 'set'
22+ | 'date'
2223 | 'string'
2324 | 'symbol'
2425 | 'undefined' ;
2526
2627// get the type of a value with handling the edge cases like `typeof []`
2728// and `typeof null`
2829const getType = ( value : any ) : ValueType => {
29- if ( typeof value === ' undefined' ) {
30+ if ( value === undefined ) {
3031 return 'undefined' ;
3132 } else if ( value === null ) {
3233 return 'null' ;
@@ -47,6 +48,8 @@ const getType = (value: any): ValueType => {
4748 return 'map' ;
4849 } else if ( value . constructor === Set ) {
4950 return 'set' ;
51+ } else if ( value . constructor === Date ) {
52+ return 'date' ;
5053 }
5154 return 'object' ;
5255 // $FlowFixMe https://github.com/facebook/flow/issues/1015
You can’t perform that action at this time.
0 commit comments