@@ -43,7 +43,7 @@ describe('q', function() {
43
43
return map ( sliceArgs ( args ) , _argToString ) . join ( ',' ) ;
44
44
}
45
45
46
- // Help log invocation of success(), always (), progress() and error()
46
+ // Help log invocation of success(), finally (), progress() and error()
47
47
function _logInvocation ( funcName , args , returnVal , throwReturnVal ) {
48
48
var logPrefix = funcName + '(' + _argumentsToString ( args ) + ')' ;
49
49
if ( throwReturnVal ) {
@@ -78,14 +78,14 @@ describe('q', function() {
78
78
/**
79
79
* Creates a callback that logs its invocation in `log`.
80
80
*
81
- * @param {(number|string) } name Suffix for 'always ' name. e.g. always (1) => always
81
+ * @param {(number|string) } name Suffix for 'finally ' name. e.g. finally (1) => finally
82
82
* @param {*= } returnVal Value that the callback should return. If unspecified, the passed in
83
83
* value is returned.
84
84
* @param {boolean= } throwReturnVal If true, the `returnVal` will be thrown rather than returned.
85
85
*/
86
- function always ( name , returnVal , throwReturnVal ) {
86
+ function fin ( name , returnVal , throwReturnVal ) {
87
87
var returnValDefined = ( arguments . length >= 2 ) ;
88
- name = 'always ' + ( name || '' ) ;
88
+ name = 'finally ' + ( name || '' ) ;
89
89
return function ( ) {
90
90
return _logInvocation ( name , arguments , ( returnValDefined ? returnVal : arguments [ 0 ] ) , throwReturnVal ) ;
91
91
}
@@ -520,8 +520,8 @@ describe('q', function() {
520
520
expect ( typeof promise [ 'catch' ] ) . toBe ( 'function' ) ;
521
521
} ) ;
522
522
523
- it ( 'should have a always method' , function ( ) {
524
- expect ( typeof promise . always ) . toBe ( 'function' ) ;
523
+ it ( 'should have a finally method' , function ( ) {
524
+ expect ( typeof promise [ 'finally' ] ) . toBe ( 'function' ) ;
525
525
} ) ;
526
526
527
527
@@ -733,51 +733,49 @@ describe('q', function() {
733
733
} ) ;
734
734
735
735
736
- describe ( 'always ' , function ( ) {
736
+ describe ( 'finally ' , function ( ) {
737
737
738
738
it ( 'should not take an argument' ,
739
739
function ( ) {
740
- promise . always ( always ( 1 ) )
740
+ promise [ 'finally' ] ( fin ( 1 ) )
741
741
syncResolve ( deferred , 'foo' ) ;
742
- expect ( logStr ( ) ) . toBe ( 'always1 ()' ) ;
742
+ expect ( logStr ( ) ) . toBe ( 'finally1 ()' ) ;
743
743
} ) ;
744
744
745
745
describe ( "when the promise is fulfilled" , function ( ) {
746
746
747
747
it ( 'should call the callback' ,
748
748
function ( ) {
749
- promise . then ( success ( 1 ) )
750
- . always ( always ( 1 ) )
749
+ promise . then ( success ( 1 ) ) [ 'finally' ] ( fin ( 1 ) )
751
750
syncResolve ( deferred , 'foo' ) ;
752
- expect ( logStr ( ) ) . toBe ( 'success1(foo)->foo; always1 ()' ) ;
751
+ expect ( logStr ( ) ) . toBe ( 'success1(foo)->foo; finally1 ()' ) ;
753
752
} ) ;
754
753
755
754
it ( 'should fulfill with the original value' ,
756
755
function ( ) {
757
- promise . always ( always ( 'B' , 'b' ) , error ( 'B' ) ) .
756
+ promise [ 'finally' ] ( fin ( 'B' , 'b' ) , error ( 'B' ) ) .
758
757
then ( success ( 'BB' , 'bb' ) , error ( 'BB' ) ) ;
759
758
syncResolve ( deferred , 'RESOLVED_VAL' ) ;
760
- expect ( log ) . toEqual ( [ 'alwaysB ()->b' ,
759
+ expect ( log ) . toEqual ( [ 'finallyB ()->b' ,
761
760
'successBB(RESOLVED_VAL)->bb' ] ) ;
762
761
} ) ;
763
762
764
763
765
764
it ( 'should fulfill with the original value (larger test)' ,
766
765
function ( ) {
767
766
promise . then ( success ( 'A' , 'a' ) , error ( 'A' ) ) ;
768
- promise . always ( always ( 'B' , 'b' ) , error ( 'B' ) ) .
767
+ promise [ 'finally' ] ( fin ( 'B' , 'b' ) , error ( 'B' ) ) .
769
768
then ( success ( 'BB' , 'bb' ) , error ( 'BB' ) ) ;
770
- promise . then ( success ( 'C' , 'c' ) , error ( 'C' ) )
771
- . always ( always ( 'CC' , 'IGNORED' ) )
769
+ promise . then ( success ( 'C' , 'c' ) , error ( 'C' ) ) [ 'finally' ] ( fin ( 'CC' , 'IGNORED' ) )
772
770
. then ( success ( 'CCC' , 'cc' ) , error ( 'CCC' ) )
773
771
. then ( success ( 'CCCC' , 'ccc' ) , error ( 'CCCC' ) )
774
772
syncResolve ( deferred , 'RESOLVED_VAL' ) ;
775
773
776
774
expect ( log ) . toEqual ( [ 'successA(RESOLVED_VAL)->a' ,
777
- 'alwaysB ()->b' ,
775
+ 'finallyB ()->b' ,
778
776
'successC(RESOLVED_VAL)->c' ,
779
777
'successBB(RESOLVED_VAL)->bb' ,
780
- 'alwaysCC ()->IGNORED' ,
778
+ 'finallyCC ()->IGNORED' ,
781
779
'successCCC(c)->cc' ,
782
780
'successCCCC(cc)->ccc' ] ) ;
783
781
} ) ;
@@ -791,12 +789,12 @@ describe('q', function() {
791
789
var returnedDef = defer ( ) ;
792
790
returnedDef . resolve ( 'bar' ) ;
793
791
794
- promise . always ( always ( 1 , returnedDef . promise ) )
792
+ promise [ 'finally' ] ( fin ( 1 , returnedDef . promise ) )
795
793
. then ( success ( 2 ) )
796
794
797
795
syncResolve ( deferred , 'foo' ) ;
798
796
799
- expect ( logStr ( ) ) . toBe ( 'always1 ()->{}; success2(foo)->foo' ) ;
797
+ expect ( logStr ( ) ) . toBe ( 'finally1 ()->{}; success2(foo)->foo' ) ;
800
798
} ) ;
801
799
} ) ;
802
800
@@ -805,21 +803,21 @@ describe('q', function() {
805
803
function ( ) {
806
804
var returnedDef = defer ( )
807
805
returnedDef . reject ( 'bar' ) ;
808
- promise . always ( always ( 1 , returnedDef . promise ) )
806
+ promise [ 'finally' ] ( fin ( 1 , returnedDef . promise ) )
809
807
. then ( success ( 2 ) , error ( 1 ) )
810
808
syncResolve ( deferred , 'foo' ) ;
811
- expect ( logStr ( ) ) . toBe ( 'always1 ()->{}; error1(bar)->reject(bar)' ) ;
809
+ expect ( logStr ( ) ) . toBe ( 'finally1 ()->{}; error1(bar)->reject(bar)' ) ;
812
810
} ) ;
813
811
} ) ;
814
812
815
813
} ) ;
816
814
817
815
describe ( "when the callback throws an exception" , function ( ) {
818
816
it ( "should reject with this new exception" , function ( ) {
819
- promise . always ( always ( 1 , "exception" , true ) )
817
+ promise [ 'finally' ] ( fin ( 1 , "exception" , true ) )
820
818
. then ( success ( 1 ) , error ( 2 ) )
821
819
syncResolve ( deferred , 'foo' ) ;
822
- expect ( logStr ( ) ) . toBe ( 'always1 ()->throw(exception); error2(exception)->reject(exception)' ) ;
820
+ expect ( logStr ( ) ) . toBe ( 'finally1 ()->throw(exception); error2(exception)->reject(exception)' ) ;
823
821
} ) ;
824
822
} ) ;
825
823
@@ -829,17 +827,17 @@ describe('q', function() {
829
827
describe ( "when the promise is rejected" , function ( ) {
830
828
831
829
it ( "should call the callback" , function ( ) {
832
- promise . always ( always ( 1 ) )
830
+ promise [ 'finally' ] ( fin ( 1 ) )
833
831
. then ( success ( 2 ) , error ( 1 ) )
834
832
syncReject ( deferred , 'foo' ) ;
835
- expect ( logStr ( ) ) . toBe ( 'always1 (); error1(foo)->reject(foo)' ) ;
833
+ expect ( logStr ( ) ) . toBe ( 'finally1 (); error1(foo)->reject(foo)' ) ;
836
834
} ) ;
837
835
838
836
it ( 'should reject with the original reason' , function ( ) {
839
- promise . always ( always ( 1 ) , "hello" )
837
+ promise [ 'finally' ] ( fin ( 1 ) , "hello" )
840
838
. then ( success ( 2 ) , error ( 2 ) )
841
839
syncReject ( deferred , 'original' ) ;
842
- expect ( logStr ( ) ) . toBe ( 'always1 (); error2(original)->reject(original)' ) ;
840
+ expect ( logStr ( ) ) . toBe ( 'finally1 (); error2(original)->reject(original)' ) ;
843
841
} ) ;
844
842
845
843
describe ( "when the callback returns a promise" , function ( ) {
@@ -849,10 +847,10 @@ describe('q', function() {
849
847
it ( "should reject with the original reason after that promise resolves" , function ( ) {
850
848
var returnedDef = defer ( )
851
849
returnedDef . resolve ( 'bar' ) ;
852
- promise . always ( always ( 1 , returnedDef . promise ) )
850
+ promise [ 'finally' ] ( fin ( 1 , returnedDef . promise ) )
853
851
. then ( success ( 2 ) , error ( 2 ) )
854
852
syncReject ( deferred , 'original' ) ;
855
- expect ( logStr ( ) ) . toBe ( 'always1 ()->{}; error2(original)->reject(original)' ) ;
853
+ expect ( logStr ( ) ) . toBe ( 'finally1 ()->{}; error2(original)->reject(original)' ) ;
856
854
} ) ;
857
855
858
856
} ) ;
@@ -862,10 +860,10 @@ describe('q', function() {
862
860
it ( "should reject with the new reason" , function ( ) {
863
861
var returnedDef = defer ( )
864
862
returnedDef . reject ( 'bar' ) ;
865
- promise . always ( always ( 1 , returnedDef . promise ) )
863
+ promise [ 'finally' ] ( fin ( 1 , returnedDef . promise ) )
866
864
. then ( success ( 2 ) , error ( 1 ) )
867
865
syncResolve ( deferred , 'foo' ) ;
868
- expect ( logStr ( ) ) . toBe ( 'always1 ()->{}; error1(bar)->reject(bar)' ) ;
866
+ expect ( logStr ( ) ) . toBe ( 'finally1 ()->{}; error1(bar)->reject(bar)' ) ;
869
867
} ) ;
870
868
871
869
} ) ;
@@ -875,10 +873,10 @@ describe('q', function() {
875
873
describe ( "when the callback throws an exception" , function ( ) {
876
874
877
875
it ( "should reject with this new exception" , function ( ) {
878
- promise . always ( always ( 1 , "exception" , true ) )
876
+ promise [ 'finally' ] ( fin ( 1 , "exception" , true ) )
879
877
. then ( success ( 1 ) , error ( 2 ) )
880
878
syncResolve ( deferred , 'foo' ) ;
881
- expect ( logStr ( ) ) . toBe ( 'always1 ()->throw(exception); error2(exception)->reject(exception)' ) ;
879
+ expect ( logStr ( ) ) . toBe ( 'finally1 ()->throw(exception); error2(exception)->reject(exception)' ) ;
882
880
} ) ;
883
881
884
882
} ) ;
0 commit comments