@@ -25,35 +25,56 @@ const mockErrorDescriptor = {
25
25
describe ( "HardhatError" , ( ) => {
26
26
describe ( "Type guard" , ( ) => {
27
27
it ( "Should return true for HardhatErrors" , ( ) => {
28
+ const error = new HardhatError ( mockErrorDescriptor ) ;
28
29
assert . ok (
29
- HardhatError . isHardhatError ( new HardhatError ( mockErrorDescriptor ) ) ,
30
+ HardhatError . isHardhatError ( error ) ,
31
+ `error ${ error . number } is a HardhatError, but isHardhatError returned false` ,
30
32
) ;
31
33
} ) ;
32
34
33
35
it ( "Should return true for HardhatErrors with the same ErrorDescriptor" , ( ) => {
36
+ const error = new HardhatError ( mockErrorDescriptor ) ;
34
37
assert . ok (
35
- HardhatError . isHardhatError (
36
- new HardhatError ( mockErrorDescriptor ) ,
37
- mockErrorDescriptor ,
38
- ) ,
38
+ HardhatError . isHardhatError ( error , mockErrorDescriptor ) ,
39
+ `error ${ error . number } matches the descriptor ${ JSON . stringify ( mockErrorDescriptor , null , 2 ) } , but isHardhatError returned false` ,
39
40
) ;
40
41
} ) ;
41
42
42
43
it ( "Should return false for everything else" , ( ) => {
43
- assert . ok ( ! HardhatError . isHardhatError ( new Error ( ) ) ) ;
44
- assert . ok ( ! HardhatError . isHardhatError ( undefined ) ) ;
45
- assert . ok ( ! HardhatError . isHardhatError ( null ) ) ;
46
- assert . ok ( ! HardhatError . isHardhatError ( 123 ) ) ;
47
- assert . ok ( ! HardhatError . isHardhatError ( "123" ) ) ;
48
- assert . ok ( ! HardhatError . isHardhatError ( { asd : 123 } ) ) ;
44
+ assert . ok (
45
+ ! HardhatError . isHardhatError ( new Error ( ) ) ,
46
+ "new Error() is not a HardhatError, but isHardhatError returned true" ,
47
+ ) ;
48
+ assert . ok (
49
+ ! HardhatError . isHardhatError ( undefined ) ,
50
+ "undefined is not a HardhatError, but isHardhatError returned true" ,
51
+ ) ;
52
+ assert . ok (
53
+ ! HardhatError . isHardhatError ( null ) ,
54
+ "null is not a HardhatError, but isHardhatError returned true" ,
55
+ ) ;
56
+ assert . ok (
57
+ ! HardhatError . isHardhatError ( 123 ) ,
58
+ "123 is not a HardhatError, but isHardhatError returned true" ,
59
+ ) ;
60
+ assert . ok (
61
+ ! HardhatError . isHardhatError ( "123" ) ,
62
+ '"123" is not a HardhatError, but isHardhatError returned true' ,
63
+ ) ;
64
+ assert . ok (
65
+ ! HardhatError . isHardhatError ( { asd : 123 } ) ,
66
+ "{ asd: 123 } is not a HardhatError, but isHardhatError returned true" ,
67
+ ) ;
49
68
} ) ;
50
69
51
70
it ( "Should return false for HardhatErrors with a different ErrorDescriptor" , ( ) => {
71
+ const error = new HardhatError ( mockErrorDescriptor ) ;
52
72
assert . ok (
53
- ! HardhatError . isHardhatError ( new HardhatError ( mockErrorDescriptor ) , {
73
+ ! HardhatError . isHardhatError ( error , {
54
74
...mockErrorDescriptor ,
55
75
number : 1 ,
56
76
} ) ,
77
+ `error ${ error . number } doesn't match the descriptor ${ JSON . stringify ( mockErrorDescriptor , null , 2 ) } , but isHardhatError returned true` ,
57
78
) ;
58
79
} ) ;
59
80
} ) ;
@@ -400,7 +421,7 @@ describe("Type tests", () => {
400
421
describe ( "Edge cases" , ( ) => {
401
422
it ( "Should support {}" , ( ) => {
402
423
expectTypeOf < MessagetTemplateArguments < "foo {} {}" > > ( ) . toEqualTypeOf < {
403
- /* eslint-disable-next-line @typescript-eslint/naming-convention --
424
+ /* eslint-disable-next-line @typescript-eslint/naming-convention --
404
425
This test case is intentionally testing a weird variable name */
405
426
"" : ErrorMessageTemplateValue ;
406
427
} > ( ) ;
0 commit comments