@@ -214,6 +214,7 @@ const makeThrowingMatcher = (
214214 result = matcher . apply ( matcherContext , [ actual ] . concat ( args ) ) ;
215215 } catch ( error ) {
216216 if (
217+ matcher . __jestInternal === true &&
217218 ! ( error instanceof JestAssertionError ) &&
218219 error . name !== 'PrettyFormatPluginError' &&
219220 // Guard for some environments (browsers) that do not support this feature.
@@ -252,7 +253,8 @@ const makeThrowingMatcher = (
252253 } ;
253254} ;
254255
255- expect . extend = ( matchers : MatchersObject ) : void => setMatchers ( matchers ) ;
256+ expect . extend = ( matchers : MatchersObject ) : void =>
257+ setMatchers ( matchers , false ) ;
256258
257259expect . anything = anything ;
258260expect . any = any ;
@@ -280,9 +282,9 @@ const _validateResult = result => {
280282} ;
281283
282284// add default jest matchers
283- expect . extend ( matchers ) ;
284- expect . extend ( spyMatchers ) ;
285- expect . extend ( toThrowMatchers ) ;
285+ setMatchers ( matchers , true ) ;
286+ setMatchers ( spyMatchers , true ) ;
287+ setMatchers ( toThrowMatchers , true ) ;
286288
287289expect . addSnapshotSerializer = ( ) => void 0 ;
288290expect . assertions = ( expected : number ) => {
@@ -296,4 +298,8 @@ expect.getState = getState;
296298expect . setState = setState ;
297299expect . extractExpectedAssertionsErrors = extractExpectedAssertionsErrors ;
298300
301+ // Expose JestAssertionError for custom matchers
302+ // This enables them to preserve the stack for specific errors
303+ expect . JestAssertionError = JestAssertionError ;
304+
299305module . exports = ( expect : Expect ) ;
0 commit comments