22'use strict' ;
33
44var TraceKit = require ( '../../vendor/TraceKit/tracekit' ) ;
5+ var utils = require ( '../../src/utils' ) ;
6+ var supportsErrorEvent = utils . supportsErrorEvent ;
57
68describe ( 'TraceKit' , function ( ) {
79 describe ( 'stacktrace info' , function ( ) {
@@ -139,9 +141,35 @@ describe('TraceKit', function() {
139141 }
140142 } ) ;
141143
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+
142170 describe ( 'with undefined arguments' , function ( ) {
143171 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
145173 // that it doesn't change unintentionally
146174 subscriptionHandler = function ( stackInfo , extra ) {
147175 assert . equal ( stackInfo . name , undefined ) ;
@@ -151,6 +179,7 @@ describe('TraceKit', function() {
151179 window . onerror ( undefined , undefined , testLineNo ) ;
152180 } ) ;
153181 } ) ;
182+
154183 describe ( 'when no 5th argument (error object)' , function ( ) {
155184 it ( 'should seperate name, message for default error types (e.g. ReferenceError)' , function (
156185 done
0 commit comments