@@ -494,6 +494,33 @@ func NotHasSuffixStringNow(t *testing.T, str, suffix string, message ...any) err
494
494
return tryNotHasSuffixString (t , true , str , suffix , message ... )
495
495
}
496
496
497
+ // IsError tests whether the error matches the target or not. It'll set the result to fail if the
498
+ // error does not match to the target error, and it doesn't stop the execution.
499
+ //
500
+ // err1 := errors.New("error 1")
501
+ // err2 := errors.New("error 2")
502
+ // assert.IsError(t, err1, err1) // success
503
+ // assert.IsError(t, err1, err2) // fail
504
+ // assert.IsError(t, errors.Join(err1, err2), err1) // success
505
+ // assert.IsError(t, errors.Join(err1, err2), err2) // success
506
+ func IsError (t * testing.T , err , target error , message ... any ) error {
507
+ return isError (t , false , err , target , message ... )
508
+ }
509
+
510
+ // IsErrorNow tests whether the error matches the target or not. It'll set the result to fail and
511
+ // stop the execution if the error does not match to the target error.
512
+ //
513
+ // err1 := errors.New("error 1")
514
+ // err2 := errors.New("error 2")
515
+ // assert.IsErrorNow(t, errors.Join(err1, err2), err1) // success
516
+ // assert.IsErrorNow(t, errors.Join(err1, err2), err2) // success
517
+ // assert.IsErrorNow(t, err1, err1) // success
518
+ // assert.IsErrorNow(t, err1, err2) // fail
519
+ // // never runs
520
+ func IsErrorNow (t * testing.T , err , target error , message ... any ) error {
521
+ return isError (t , true , err , target , message ... )
522
+ }
523
+
497
524
// MapHasKey tests whether the map contains the specified key or not, it will fail if the map does
498
525
// not contain the key, or the type of the key cannot assign to the type of the key of the map.
499
526
//
0 commit comments