File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -106,19 +106,25 @@ describe('utils', () => {
106
106
107
107
it ( 'hashThisString()' , ( ) => {
108
108
const hash1 = hashThisString ( 'a' ) ;
109
+ const hashNull = hashThisString ( '[ type: null ; value: ""]' ) ;
110
+ const empty = hashThisString ( '' ) ;
109
111
const hash2 = hashThisString ( 'abc' ) ;
110
112
const hash3 = hashThisString ( 'abcsydghcsdagcyasjdcsdvcgsavdgcvsagdcbjhsdbbc' ) ;
111
113
112
114
expect ( hash1 ) . toBe ( 97 ) ;
115
+ expect ( empty ) . toBe ( 0 ) ;
116
+ expect ( hashNull ) . toBe ( 1593002687 ) ;
113
117
expect ( hash2 ) . toBe ( 96354 ) ;
114
118
expect ( hash3 ) . toBe ( 25191889 ) ;
115
119
} ) ;
116
120
117
121
it ( 'getOrderIndependentHash()' , ( ) => {
118
122
const array = getOrderIndependentHash ( [ 'a' , 'b' ] ) ;
123
+ const ifNull = getOrderIndependentHash ( null ) ;
119
124
const obj = getOrderIndependentHash ( { a : 'a' , b : 'b' } ) ;
120
125
const string = getOrderIndependentHash ( 'ab' ) ;
121
126
127
+ expect ( ifNull ) . toBe ( 1933772593 ) ;
122
128
expect ( array ) . toBe ( 976844698 ) ;
123
129
expect ( obj ) . toBe ( - 2385456289 ) ;
124
130
expect ( string ) . toBe ( 35072500 ) ;
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ export const realTypeOf = (obj: any): string => {
65
65
if ( Object . prototype . toString . call ( obj ) === '[object Date]' ) {
66
66
return 'date' ;
67
67
}
68
- if ( typeof obj . toString === 'function' && / ^ \/ .* \/ / . test ( obj . toString ( ) ) ) {
68
+ if ( typeof obj ? .toString === 'function' && / ^ \/ .* \/ / . test ( obj . toString ( ) ) ) {
69
69
return 'regexp' ;
70
70
}
71
71
return 'object' ;
@@ -110,7 +110,8 @@ export const getOrderIndependentHash = (obj: any): number => {
110
110
} ) ;
111
111
return accum ;
112
112
}
113
- const stringToHash = `[ type: ${ type } ; value: ${ obj . toString ( ) } ]` ;
113
+
114
+ const stringToHash = `[ type: ${ type } ; value: ${ obj ? obj . toString ( ) : 'hash' } ]` ;
114
115
return accum + hashThisString ( stringToHash ) ;
115
116
} ;
116
117
You can’t perform that action at this time.
0 commit comments