@@ -275,7 +275,11 @@ describe('miscellaneous', function() {
275
275
var objAgain = new Parse . Object ( 'BeforeDeleteFail' , { objectId : id } ) ;
276
276
return objAgain . fetch ( ) ;
277
277
} ) . 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
+ }
279
283
done ( ) ;
280
284
} , ( error ) => {
281
285
// We should have been able to fetch the object again
@@ -351,6 +355,11 @@ describe('miscellaneous', function() {
351
355
it ( 'test cloud function return types' , function ( done ) {
352
356
Parse . Cloud . run ( 'foo' ) . then ( ( result ) => {
353
357
expect ( result . object instanceof Parse . Object ) . toBeTruthy ( ) ;
358
+ if ( ! result . object ) {
359
+ fail ( "Unable to run foo" ) ;
360
+ done ( ) ;
361
+ return ;
362
+ }
354
363
expect ( result . object . className ) . toEqual ( 'Foo' ) ;
355
364
expect ( result . object . get ( 'x' ) ) . toEqual ( 2 ) ;
356
365
var bar = result . object . get ( 'relation' ) ;
@@ -381,23 +390,25 @@ describe('miscellaneous', function() {
381
390
expect ( results . length ) . toEqual ( 1 ) ;
382
391
expect ( results [ 0 ] [ 'foo' ] ) . toEqual ( 'bar' ) ;
383
392
done ( ) ;
384
- } ) ;
393
+ } ) . fail ( err => {
394
+ fail ( err ) ;
395
+ done ( ) ;
396
+ } )
385
397
} ) ;
386
398
387
399
describe ( 'beforeSave' , ( ) => {
388
400
beforeEach ( done => {
389
401
// Make sure the required mock for all tests is unset.
390
- delete Parse . Cloud . Triggers . beforeSave . GameScore ;
402
+ Parse . Cloud . _removeHook ( " Triggers" , " beforeSave" , " GameScore" ) ;
391
403
done ( ) ;
392
404
} ) ;
393
-
394
405
afterEach ( done => {
395
406
// Make sure the required mock for all tests is unset.
396
- delete Parse . Cloud . Triggers . beforeSave . GameScore ;
407
+ Parse . Cloud . _removeHook ( " Triggers" , " beforeSave" , " GameScore" ) ;
397
408
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 => {
401
412
let triggerTime = 0 ;
402
413
// Register a mock beforeSave hook
403
414
Parse . Cloud . beforeSave ( 'GameScore' , ( req , res ) => {
@@ -610,8 +621,8 @@ describe('miscellaneous', function() {
610
621
} ) . then ( function ( ) {
611
622
// Make sure the checking has been triggered
612
623
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" ) ;
615
626
done ( ) ;
616
627
} , function ( error ) {
617
628
fail ( error ) ;
@@ -663,9 +674,10 @@ describe('miscellaneous', function() {
663
674
// Make sure the checking has been triggered
664
675
expect ( triggerTime ) . toBe ( 2 ) ;
665
676
// Clear mock afterSave
666
- delete Parse . Cloud . Triggers . afterSave . GameScore ;
677
+ Parse . Cloud . _removeHook ( " Triggers" , " afterSave" , " GameScore" ) ;
667
678
done ( ) ;
668
679
} , function ( error ) {
680
+ console . error ( error ) ;
669
681
fail ( error ) ;
670
682
done ( ) ;
671
683
} ) ;
@@ -678,12 +690,12 @@ describe('miscellaneous', function() {
678
690
} ) ;
679
691
Parse . Cloud . run ( 'willFail' ) . then ( ( s ) => {
680
692
fail ( 'Should not have succeeded.' ) ;
681
- delete Parse . Cloud . Functions [ ' willFail' ] ;
693
+ Parse . Cloud . _removeHook ( " Functions" , " willFail" ) ;
682
694
done ( ) ;
683
695
} , ( e ) => {
684
696
expect ( e . code ) . toEqual ( 141 ) ;
685
697
expect ( e . message ) . toEqual ( 'noway' ) ;
686
- delete Parse . Cloud . Functions [ ' willFail' ] ;
698
+ Parse . Cloud . _removeHook ( " Functions" , " willFail" ) ;
687
699
done ( ) ;
688
700
} ) ;
689
701
} ) ;
@@ -712,7 +724,7 @@ describe('miscellaneous', function() {
712
724
// Make sure query string params override body params
713
725
expect ( res . other ) . toEqual ( '2' ) ;
714
726
expect ( res . foo ) . toEqual ( "bar" ) ;
715
- delete Parse . Cloud . Functions [ 'echoParams' ] ;
727
+ Parse . Cloud . _removeHook ( " Functions" , 'echoParams' ) ;
716
728
done ( ) ;
717
729
} ) ;
718
730
} ) ;
@@ -726,7 +738,7 @@ describe('miscellaneous', function() {
726
738
} ) ;
727
739
728
740
Parse . Cloud . run ( 'functionWithParameterValidation' , { "success" :100 } ) . then ( ( s ) => {
729
- delete Parse . Cloud . Functions [ ' functionWithParameterValidation' ] ;
741
+ Parse . Cloud . _removeHook ( " Functions" , " functionWithParameterValidation" ) ;
730
742
done ( ) ;
731
743
} , ( e ) => {
732
744
fail ( 'Validation should not have failed.' ) ;
@@ -744,7 +756,7 @@ describe('miscellaneous', function() {
744
756
745
757
Parse . Cloud . run ( 'functionWithParameterValidationFailure' , { "success" :500 } ) . then ( ( s ) => {
746
758
fail ( 'Validation should not have succeeded' ) ;
747
- delete Parse . Cloud . Functions [ ' functionWithParameterValidationFailure' ] ;
759
+ Parse . Cloud . _removeHook ( " Functions" , " functionWithParameterValidationFailure" ) ;
748
760
done ( ) ;
749
761
} , ( e ) => {
750
762
expect ( e . code ) . toEqual ( 141 ) ;
0 commit comments