@@ -128,13 +128,26 @@ test('end can be used as callback without maintaining thisArg', function (t) {
128128} ) ;
129129
130130test ( 'end can be used as callback with error' , function ( t ) {
131+ var err = new Error ( 'failed' ) ;
131132 ava . cb ( function ( a ) {
132- a . end ( new Error ( 'failed' ) ) ;
133+ a . end ( err ) ;
133134 } ) . run ( ) . then ( function ( result ) {
134135 t . is ( result . passed , false ) ;
135- t . true ( result . reason instanceof Error ) ;
136- // TODO: Question - why not just set the reason to the error?
137- t . match ( result . reason . message , / C a l l b a c k c a l l e d w i t h a n e r r o r / ) ;
136+ t . is ( result . reason , err ) ;
137+ t . end ( ) ;
138+ } ) ;
139+ } ) ;
140+
141+ test ( 'end can be used as callback with a non-error as its error argument' , function ( t ) {
142+ var nonError = { foo : 'bar' } ;
143+ ava . cb ( function ( a ) {
144+ a . end ( nonError ) ;
145+ } ) . run ( ) . then ( function ( result ) {
146+ t . is ( result . passed , false ) ;
147+ t . ok ( result . reason ) ;
148+ t . is ( result . reason . name , 'AssertionError' ) ;
149+ t . is ( result . reason . actual , nonError ) ;
150+ t . is ( result . reason . message , 'Callback called with an error: { foo: \'bar\' }' ) ;
138151 t . end ( ) ;
139152 } ) ;
140153} ) ;
@@ -364,17 +377,24 @@ test('fails with thrown falsy value', function (t) {
364377 } ) . run ( ) ;
365378
366379 t . is ( result . passed , false ) ;
367- t . is ( result . reason , 0 ) ;
380+ t . is ( result . reason . actual , 0 ) ;
381+ t . is ( result . reason . message , 'Non-error thrown with value: 0' ) ;
382+ t . is ( result . reason . name , 'AssertionError' ) ;
383+ t . is ( result . reason . operator , 'catch' ) ;
368384 t . end ( ) ;
369385} ) ;
370386
371- test ( 'throwing undefined will be converted to string "undefined"' , function ( t ) {
387+ test ( 'fails with thrown non-error object' , function ( t ) {
388+ var obj = { foo : 'bar' } ;
372389 var result = ava ( function ( ) {
373- throw undefined ; // eslint-disable-line no-throw-literal
390+ throw obj ;
374391 } ) . run ( ) ;
375392
376393 t . is ( result . passed , false ) ;
377- t . is ( result . reason , 'undefined' ) ;
394+ t . is ( result . reason . actual , obj ) ;
395+ t . is ( result . reason . message , 'Non-error thrown with value: { foo: \'bar\' }' ) ;
396+ t . is ( result . reason . name , 'AssertionError' ) ;
397+ t . is ( result . reason . operator , 'catch' ) ;
378398 t . end ( ) ;
379399} ) ;
380400
0 commit comments