@@ -34,6 +34,57 @@ it("ExceptionOptionType allows specifying message", () => {
34
34
expect ( exception . code ) . toBe ( "code" ) ;
35
35
} ) ;
36
36
37
+ describe ( "ServiceException type checking" , ( ) => {
38
+ const error = new ServiceException ( {
39
+ name : "Error" ,
40
+ $fault : "client" ,
41
+ $metadata : { } ,
42
+ } ) ;
43
+
44
+ const duckTyped = {
45
+ $fault : "server" ,
46
+ $metadata : { } ,
47
+ } ;
48
+
49
+ describe ( "isInstance" , ( ) => {
50
+ it ( "should return true for ServiceException instances" , ( ) => {
51
+ expect ( ServiceException . isInstance ( error ) ) . toBe ( true ) ;
52
+ } ) ;
53
+
54
+ it ( "should return true for duck-typed objects" , ( ) => {
55
+ expect ( ServiceException . isInstance ( duckTyped ) ) . toBe ( true ) ;
56
+ } ) ;
57
+
58
+ it ( "should return false for null or undefined" , ( ) => {
59
+ expect ( ServiceException . isInstance ( null ) ) . toBe ( false ) ;
60
+ expect ( ServiceException . isInstance ( undefined ) ) . toBe ( false ) ;
61
+ } ) ;
62
+
63
+ it ( "should return false for invalid $fault values" , ( ) => {
64
+ expect ( ServiceException . isInstance ( { $fault : "invalid" , $metadata : { } } ) ) . toBe ( false ) ;
65
+ } ) ;
66
+
67
+ it ( "should return false for missing properties" , ( ) => {
68
+ expect ( ServiceException . isInstance ( { $fault : "client" } ) ) . toBe ( false ) ;
69
+ expect ( ServiceException . isInstance ( { $metadata : { } } ) ) . toBe ( false ) ;
70
+ } ) ;
71
+ } ) ;
72
+
73
+ describe ( "instanceof" , ( ) => {
74
+ it ( "should return true for ServiceException instances" , ( ) => {
75
+ expect ( error instanceof ServiceException ) . toBe ( true ) ;
76
+ } ) ;
77
+
78
+ it ( "should return true for duck-typed objects" , ( ) => {
79
+ expect ( duckTyped instanceof ServiceException ) . toBe ( true ) ;
80
+ } ) ;
81
+
82
+ it ( "should return false for invalid objects" , ( ) => {
83
+ expect ( { } instanceof ServiceException ) . toBe ( false ) ;
84
+ } ) ;
85
+ } ) ;
86
+ } ) ;
87
+
37
88
describe ( "decorateServiceException" , ( ) => {
38
89
const exception = new ServiceException ( {
39
90
name : "Error" ,
0 commit comments