@@ -58,4 +58,45 @@ describe("Base telemetry sender test suite", () => {
58
58
assert . strictEqual ( sender . _exceptionQueue . length , 0 ) ;
59
59
assert . strictEqual ( ( telemetryClient . logEvent as sinon . SinonSpy ) . callCount , 1 ) ;
60
60
} ) ;
61
- } ) ;
61
+
62
+ describe ( "Send error data logic" , ( ) => {
63
+ let sender : BaseTelemetrySender ;
64
+
65
+ beforeEach ( async ( ) => {
66
+ sender = new BaseTelemetrySender ( "key" , telemetryClientFactory ) ;
67
+ sender . instantiateSender ( ) ;
68
+ // Wait 10ms to ensure that the sender has instantiated the client
69
+ await new Promise ( ( resolve ) => setTimeout ( resolve , 10 ) ) ;
70
+ } ) ;
71
+
72
+ it ( "Error properties are correctly created for an empty data argument" , ( ) => {
73
+ const error = new Error ( "test" ) ;
74
+ sender . sendErrorData ( error ) ;
75
+ assert . strictEqual ( ( telemetryClient . logEvent as sinon . SinonSpy ) . callCount , 1 ) ;
76
+ sinon . assert . calledWithMatch (
77
+ telemetryClient . logEvent as sinon . SinonSpy , "unhandlederror" ,
78
+ { properties : { name : error . name , message : error . message , stack : error . stack } }
79
+ ) ;
80
+ } )
81
+
82
+ it ( "Error properties are correctly created for a data without properties field" , ( ) => {
83
+ const error = new Error ( "test" ) ;
84
+ sender . sendErrorData ( error , { prop1 : 1 , prop2 : "two" } ) ;
85
+ assert . strictEqual ( ( telemetryClient . logEvent as sinon . SinonSpy ) . callCount , 1 ) ;
86
+ sinon . assert . calledWithMatch (
87
+ telemetryClient . logEvent as sinon . SinonSpy , "unhandlederror" ,
88
+ { properties : { prop1 : 1 , prop2 : "two" , name : error . name , message : error . message , stack : error . stack } }
89
+ ) ;
90
+ } ) ;
91
+
92
+ it ( "Error properties are correctly created for a data with properties field" , ( ) => {
93
+ const error = new Error ( "uh oh" ) ;
94
+ sender . sendErrorData ( error , { properties : { prop1 : 1 , prop2 : "two" } } ) ;
95
+ assert . strictEqual ( ( telemetryClient . logEvent as sinon . SinonSpy ) . callCount , 1 ) ;
96
+ sinon . assert . calledWithMatch (
97
+ telemetryClient . logEvent as sinon . SinonSpy , "unhandlederror" ,
98
+ { properties : { prop1 : 1 , prop2 : "two" , name : error . name , message : error . message , stack : error . stack } }
99
+ ) ;
100
+ } ) ;
101
+ } )
102
+ } ) ;
0 commit comments