2
2
'use strict' ;
3
3
4
4
var TraceKit = require ( '../../vendor/TraceKit/tracekit' ) ;
5
+ var utils = require ( '../../src/utils' ) ;
6
+ var supportsErrorEvent = utils . supportsErrorEvent ;
5
7
6
8
describe ( 'TraceKit' , function ( ) {
7
9
describe ( 'stacktrace info' , function ( ) {
@@ -139,9 +141,35 @@ describe('TraceKit', function() {
139
141
}
140
142
} ) ;
141
143
144
+ if ( supportsErrorEvent ( ) ) {
145
+ it ( "should handle error event object as 'ex' param" , function ( ) {
146
+ var ex = new ErrorEvent ( '' , {
147
+ error : new Error ( 'something went wrong' )
148
+ } ) ;
149
+ subscriptionHandler = function ( stackInfo , extra ) {
150
+ assert . equal ( stackInfo . name , 'Error' ) ;
151
+ assert . equal ( stackInfo . message , 'something went wrong' ) ;
152
+ } ;
153
+ TraceKit . report . subscribe ( subscriptionHandler ) ;
154
+ window . onerror ( undefined , undefined , testLineNo , undefined , ex ) ;
155
+ } ) ;
156
+
157
+ it ( "should handle error event object as 'message' param" , function ( ) {
158
+ var message = new ErrorEvent ( '' , {
159
+ message : 'something went wrong'
160
+ } ) ;
161
+ subscriptionHandler = function ( stackInfo , extra ) {
162
+ assert . equal ( stackInfo . name , undefined ) ;
163
+ assert . equal ( stackInfo . message , 'something went wrong' ) ;
164
+ } ;
165
+ TraceKit . report . subscribe ( subscriptionHandler ) ;
166
+ window . onerror ( message , undefined , testLineNo , undefined , undefined ) ;
167
+ } ) ;
168
+ }
169
+
142
170
describe ( 'with undefined arguments' , function ( ) {
143
171
it ( 'should pass undefined:undefined' , function ( ) {
144
- // this is probably not good behavior; just writing this test to verify
172
+ // this is probably not good behavior; just writing this test to verify
145
173
// that it doesn't change unintentionally
146
174
subscriptionHandler = function ( stackInfo , extra ) {
147
175
assert . equal ( stackInfo . name , undefined ) ;
@@ -151,6 +179,7 @@ describe('TraceKit', function() {
151
179
window . onerror ( undefined , undefined , testLineNo ) ;
152
180
} ) ;
153
181
} ) ;
182
+
154
183
describe ( 'when no 5th argument (error object)' , function ( ) {
155
184
it ( 'should seperate name, message for default error types (e.g. ReferenceError)' , function (
156
185
done
0 commit comments