@@ -275,7 +275,11 @@ describe('miscellaneous', function() {
275275 var objAgain = new Parse . Object ( 'BeforeDeleteFail' , { objectId : id } ) ;
276276 return objAgain . fetch ( ) ;
277277 } ) . then ( ( objAgain ) => {
278- expect ( objAgain . get ( 'foo' ) ) . toEqual ( 'bar' ) ;
278+ if ( objAgain ) {
279+ expect ( objAgain . get ( 'foo' ) ) . toEqual ( 'bar' ) ;
280+ } else {
281+ fail ( "unable to fetch the object " , id ) ;
282+ }
279283 done ( ) ;
280284 } , ( error ) => {
281285 // We should have been able to fetch the object again
@@ -351,6 +355,11 @@ describe('miscellaneous', function() {
351355 it ( 'test cloud function return types' , function ( done ) {
352356 Parse . Cloud . run ( 'foo' ) . then ( ( result ) => {
353357 expect ( result . object instanceof Parse . Object ) . toBeTruthy ( ) ;
358+ if ( ! result . object ) {
359+ fail ( "Unable to run foo" ) ;
360+ done ( ) ;
361+ return ;
362+ }
354363 expect ( result . object . className ) . toEqual ( 'Foo' ) ;
355364 expect ( result . object . get ( 'x' ) ) . toEqual ( 2 ) ;
356365 var bar = result . object . get ( 'relation' ) ;
@@ -381,23 +390,25 @@ describe('miscellaneous', function() {
381390 expect ( results . length ) . toEqual ( 1 ) ;
382391 expect ( results [ 0 ] [ 'foo' ] ) . toEqual ( 'bar' ) ;
383392 done ( ) ;
384- } ) ;
393+ } ) . fail ( err => {
394+ fail ( err ) ;
395+ done ( ) ;
396+ } )
385397 } ) ;
386398
387399 describe ( 'beforeSave' , ( ) => {
388400 beforeEach ( done => {
389401 // Make sure the required mock for all tests is unset.
390- delete Parse . Cloud . Triggers . beforeSave . GameScore ;
402+ Parse . Cloud . _removeHook ( " Triggers" , " beforeSave" , " GameScore" ) ;
391403 done ( ) ;
392404 } ) ;
393-
394405 afterEach ( done => {
395406 // Make sure the required mock for all tests is unset.
396- delete Parse . Cloud . Triggers . beforeSave . GameScore ;
407+ Parse . Cloud . _removeHook ( " Triggers" , " beforeSave" , " GameScore" ) ;
397408 done ( ) ;
398- } ) ;
399-
400- it ( 'object is set on create and update' , done => {
409+ } ) ;
410+
411+ it ( 'object is set on create and update' , done => {
401412 let triggerTime = 0 ;
402413 // Register a mock beforeSave hook
403414 Parse . Cloud . beforeSave ( 'GameScore' , ( req , res ) => {
@@ -610,8 +621,8 @@ describe('miscellaneous', function() {
610621 } ) . then ( function ( ) {
611622 // Make sure the checking has been triggered
612623 expect ( triggerTime ) . toBe ( 2 ) ;
613- // Clear mock afterSave
614- delete Parse . Cloud . Triggers . afterSave . GameScore ;
624+ // Clear mock beforeSave
625+ Parse . Cloud . _removeHook ( " Triggers" , "beforeSave" , " GameScore" ) ;
615626 done ( ) ;
616627 } , function ( error ) {
617628 fail ( error ) ;
@@ -663,9 +674,10 @@ describe('miscellaneous', function() {
663674 // Make sure the checking has been triggered
664675 expect ( triggerTime ) . toBe ( 2 ) ;
665676 // Clear mock afterSave
666- delete Parse . Cloud . Triggers . afterSave . GameScore ;
677+ Parse . Cloud . _removeHook ( " Triggers" , " afterSave" , " GameScore" ) ;
667678 done ( ) ;
668679 } , function ( error ) {
680+ console . error ( error ) ;
669681 fail ( error ) ;
670682 done ( ) ;
671683 } ) ;
@@ -678,12 +690,12 @@ describe('miscellaneous', function() {
678690 } ) ;
679691 Parse . Cloud . run ( 'willFail' ) . then ( ( s ) => {
680692 fail ( 'Should not have succeeded.' ) ;
681- delete Parse . Cloud . Functions [ ' willFail' ] ;
693+ Parse . Cloud . _removeHook ( " Functions" , " willFail" ) ;
682694 done ( ) ;
683695 } , ( e ) => {
684696 expect ( e . code ) . toEqual ( 141 ) ;
685697 expect ( e . message ) . toEqual ( 'noway' ) ;
686- delete Parse . Cloud . Functions [ ' willFail' ] ;
698+ Parse . Cloud . _removeHook ( " Functions" , " willFail" ) ;
687699 done ( ) ;
688700 } ) ;
689701 } ) ;
@@ -712,7 +724,7 @@ describe('miscellaneous', function() {
712724 // Make sure query string params override body params
713725 expect ( res . other ) . toEqual ( '2' ) ;
714726 expect ( res . foo ) . toEqual ( "bar" ) ;
715- delete Parse . Cloud . Functions [ 'echoParams' ] ;
727+ Parse . Cloud . _removeHook ( " Functions" , 'echoParams' ) ;
716728 done ( ) ;
717729 } ) ;
718730 } ) ;
@@ -726,7 +738,7 @@ describe('miscellaneous', function() {
726738 } ) ;
727739
728740 Parse . Cloud . run ( 'functionWithParameterValidation' , { "success" :100 } ) . then ( ( s ) => {
729- delete Parse . Cloud . Functions [ ' functionWithParameterValidation' ] ;
741+ Parse . Cloud . _removeHook ( " Functions" , " functionWithParameterValidation" ) ;
730742 done ( ) ;
731743 } , ( e ) => {
732744 fail ( 'Validation should not have failed.' ) ;
@@ -744,7 +756,7 @@ describe('miscellaneous', function() {
744756
745757 Parse . Cloud . run ( 'functionWithParameterValidationFailure' , { "success" :500 } ) . then ( ( s ) => {
746758 fail ( 'Validation should not have succeeded' ) ;
747- delete Parse . Cloud . Functions [ ' functionWithParameterValidationFailure' ] ;
759+ Parse . Cloud . _removeHook ( " Functions" , " functionWithParameterValidationFailure" ) ;
748760 done ( ) ;
749761 } , ( e ) => {
750762 expect ( e . code ) . toEqual ( 141 ) ;
0 commit comments