@@ -97,7 +97,11 @@ export function addCustomEqualityTester(jasmine: any) {
97
97
} ;
98
98
}
99
99
100
- export function eq ( a : any , b : any ) {
100
+ function getErrorMessage ( error : any ) {
101
+ return error . message || error . description ;
102
+ }
103
+
104
+ export function eq ( a : any , b : any ) : boolean {
101
105
for ( let i = 0 ; i < customEqualityTesters . length ; i ++ ) {
102
106
const result = customEqualityTesters [ i ] ( a , b ) ;
103
107
if ( result === true || result === false ) {
@@ -132,12 +136,13 @@ export function eq(a: any, b: any) {
132
136
if ( b instanceof ObjectContaining ) {
133
137
return b . match ( a ) ;
134
138
}
139
+ if ( a instanceof Error && b instanceof Error ) {
140
+ return getErrorMessage ( a ) === getErrorMessage ( b ) ||
141
+ toMatch ( getErrorMessage ( a ) , getErrorMessage ( b ) ) ;
142
+ }
135
143
if ( Object . keys ( a ) . length !== Object . keys ( b ) . length ) {
136
144
return false ;
137
145
}
138
- if ( a instanceof Error && b instanceof Error ) {
139
- return a . message === b . message ;
140
- }
141
146
let isEqual = true ;
142
147
143
148
for ( let prop in a ) {
@@ -156,11 +161,11 @@ export function eq(a: any, b: any) {
156
161
return b . eq ( a ) ;
157
162
}
158
163
159
- if ( a instanceof Error && typeof b === 'string' ) {
160
- return a . message === b ;
164
+ if ( a instanceof Error ) {
165
+ return eq ( getErrorMessage ( a ) , b ) || toMatch ( getErrorMessage ( a ) , b ) ;
161
166
}
162
- if ( b instanceof Error && typeof a === 'string' ) {
163
- return a === b . message ;
167
+ if ( b instanceof Error ) {
168
+ return eq ( a , getErrorMessage ( b ) ) || toMatch ( a , getErrorMessage ( b ) ) ;
164
169
}
165
170
166
171
return false ;
@@ -184,10 +189,10 @@ export function buildFailureMessage(
184
189
return ' ' + s . toLowerCase ( ) ;
185
190
} ) ;
186
191
187
- var message = 'Expected ' + formatObject ( actual ) + ( isNot ? ' not ' : ' ' ) + englishyPredicate ;
192
+ let message = 'Expected ' + formatObject ( actual ) + ( isNot ? ' not ' : ' ' ) + englishyPredicate ;
188
193
189
194
if ( expected . length > 0 ) {
190
- for ( var i = 0 ; i < expected . length ; i ++ ) {
195
+ for ( let i = 0 ; i < expected . length ; i ++ ) {
191
196
if ( i > 0 ) {
192
197
message += ',' ;
193
198
}
0 commit comments