@@ -297,16 +297,39 @@ describe.each(['toThrowError', 'toThrow'] as const)('%s', toThrow => {
297297 } ) ;
298298
299299 test ( 'isNot true, incorrect cause' , ( ) => {
300- // less than v16 does not yet support Error.cause
301- if ( Number ( process . version . split ( '.' ) [ 0 ] . slice ( 1 ) ) < 16 ) {
302- expect ( true ) . toBe ( true ) ;
303- } else {
300+ // only v16 or higher support Error.cause
301+ if ( Number ( process . version . split ( '.' ) [ 0 ] . slice ( 1 ) ) >= 16 ) {
304302 jestExpect ( ( ) => {
305303 throw new Error ( 'good' , { cause : errorA } ) ;
306304 } ) . not [ toThrow ] ( expected ) ;
307305 }
308306 } ) ;
309307 } ) ;
308+
309+ describe ( 'fail' , ( ) => {
310+ // only v16 or higher support Error.cause
311+ if ( Number ( process . version . split ( '.' ) [ 0 ] . slice ( 1 ) ) >= 16 ) {
312+ test ( 'isNot false, incorrect message' , ( ) => {
313+ expect ( ( ) =>
314+ jestExpect ( ( ) => {
315+ throw new Error ( 'bad' , { cause : errorB } ) ;
316+ } ) [ toThrow ] ( expected ) ,
317+ ) . toThrow (
318+ / ^ (? = .* E x p e c t e d m e s s a g e a n d c a u s e : ) .* R e c e i v e d m e s s a g e a n d c a u s e : / s,
319+ ) ;
320+ } ) ;
321+
322+ test ( 'isNot true, incorrect cause' , ( ) => {
323+ expect ( ( ) =>
324+ jestExpect ( ( ) => {
325+ throw new Error ( 'good' , { cause : errorA } ) ;
326+ } ) [ toThrow ] ( expected ) ,
327+ ) . toThrow (
328+ / ^ (? = .* E x p e c t e d m e s s a g e a n d c a u s e : ) .* R e c e i v e d m e s s a g e a n d c a u s e : / s,
329+ ) ;
330+ } ) ;
331+ }
332+ } ) ;
310333 } ) ;
311334
312335 describe ( 'asymmetric' , ( ) => {
0 commit comments