@@ -106,6 +106,8 @@ describe('TraceKit', function(){
106106
107107 describe ( 'error notifications' , function ( ) {
108108 var testMessage = "__mocha_ignore__" ;
109+ var testLineNo = 1337 ;
110+
109111 var subscriptionHandler ;
110112 // TraceKit waits 2000ms for window.onerror to fire, so give the tests
111113 // some extra time.
@@ -119,8 +121,8 @@ describe('TraceKit', function(){
119121 // we can't do that without clobbering TraceKit's handler, which can only
120122 // be installed once.
121123 var oldOnError = window . onerror ;
122- window . onerror = function ( message ) {
123- if ( message == testMessage ) {
124+ window . onerror = function ( message , url , lineNo ) {
125+ if ( message == testMessage || lineNo === testLineNo ) {
124126 return true ;
125127 }
126128 return oldOnError . apply ( this , arguments ) ;
@@ -134,6 +136,53 @@ describe('TraceKit', function(){
134136 }
135137 } ) ;
136138
139+ describe ( 'with undefined arguments' , function ( ) {
140+ it ( 'should pass undefined:undefined' , function ( ) {
141+ // this is probably not good behavior; just writing this test to verify
142+ // that it doesn't change unintentionally
143+ subscriptionHandler = function ( stackInfo , extra ) {
144+ assert . equal ( stackInfo . name , undefined ) ;
145+ assert . equal ( stackInfo . message , undefined ) ;
146+ } ;
147+ TraceKit . report . subscribe ( subscriptionHandler ) ;
148+ window . onerror ( undefined , undefined , testLineNo ) ;
149+ } ) ;
150+ } ) ;
151+ describe ( 'when no 5th argument (error object)' , function ( ) {
152+ it ( 'should seperate name, message for default error types (e.g. ReferenceError)' , function ( done ) {
153+ subscriptionHandler = function ( stackInfo , extra ) {
154+ assert . equal ( stackInfo . name , 'ReferenceError' ) ;
155+ assert . equal ( stackInfo . message , 'foo is undefined' ) ;
156+ } ;
157+ TraceKit . report . subscribe ( subscriptionHandler ) ;
158+ // should work with/without "Uncaught"
159+ window . onerror ( 'Uncaught ReferenceError: foo is undefined' , 'http://example.com' , testLineNo ) ;
160+ window . onerror ( 'ReferenceError: foo is undefined' , 'http://example.com' , testLineNo )
161+ done ( ) ;
162+ } ) ;
163+
164+ it ( 'should ignore unknown error types' , function ( done ) {
165+ // TODO: should we attempt to parse this?
166+ subscriptionHandler = function ( stackInfo , extra ) {
167+ assert . equal ( stackInfo . name , undefined ) ;
168+ assert . equal ( stackInfo . message , 'CustomError: woo scary' ) ;
169+ done ( ) ;
170+ } ;
171+ TraceKit . report . subscribe ( subscriptionHandler ) ;
172+ window . onerror ( 'CustomError: woo scary' , 'http://example.com' , testLineNo ) ;
173+ } ) ;
174+
175+ it ( 'should ignore arbitrary messages passed through onerror' , function ( done ) {
176+ subscriptionHandler = function ( stackInfo , extra ) {
177+ assert . equal ( stackInfo . name , undefined ) ;
178+ assert . equal ( stackInfo . message , 'all work and no play makes homer: something something' ) ;
179+ done ( ) ;
180+ } ;
181+ TraceKit . report . subscribe ( subscriptionHandler ) ;
182+ window . onerror ( 'all work and no play makes homer: something something' , 'http://example.com' , testLineNo ) ;
183+ } ) ;
184+ } ) ;
185+
137186 function testErrorNotification ( collectWindowErrors , callOnError , numReports , done ) {
138187 var extraVal = "foo" ;
139188 var numDone = 0 ;
0 commit comments