@@ -25,7 +25,7 @@ describe('Observable.prototype.catch()', function () {
25
25
26
26
it ( 'should catch error and replace it with a cold Observable' , function ( ) {
27
27
var e1 = hot ( '--a--b--#----| ' ) ;
28
- var e1subs = '^ ! ' ;
28
+ var e1subs = '^ ! ' ;
29
29
var e2 = cold ( '1-2-3-4-5-|' ) ;
30
30
var e2subs = ' ^ !' ;
31
31
var expected = '--a--b--1-2-3-4-5-|' ;
@@ -37,9 +37,23 @@ describe('Observable.prototype.catch()', function () {
37
37
expectSubscriptions ( e2 . subscriptions ) . toBe ( e2subs ) ;
38
38
} ) ;
39
39
40
+ it ( 'should allow unsubscribing explicitly and early' , function ( ) {
41
+ var e1 = hot ( '--1-2-3-4-5-6---#' ) ;
42
+ var unsub = ' ! ' ;
43
+ var e1subs = '^ ! ' ;
44
+ var expected = '--1-2-3- ' ;
45
+
46
+ var result = e1 . catch ( function ( ) {
47
+ return Observable . of ( 'X' , 'Y' , 'Z' ) ;
48
+ } ) ;
49
+
50
+ expectObservable ( result , unsub ) . toBe ( expected ) ;
51
+ expectSubscriptions ( e1 . subscriptions ) . toBe ( e1subs ) ;
52
+ } ) ;
53
+
40
54
it ( 'should catch error and replace it with a hot Observable' , function ( ) {
41
55
var e1 = hot ( '--a--b--#----| ' ) ;
42
- var e1subs = '^ ! ' ;
56
+ var e1subs = '^ ! ' ;
43
57
var e2 = hot ( '1-2-3-4-5-6-7-8-9-|' ) ;
44
58
var e2subs = ' ^ !' ;
45
59
var expected = '--a--b--5-6-7-8-9-|' ;
@@ -54,8 +68,8 @@ describe('Observable.prototype.catch()', function () {
54
68
it ( 'should catch and allow the cold observable to be repeated with the third ' +
55
69
'(caught) argument' , function ( ) {
56
70
var e1 = cold ( '--a--b--c--------| ' ) ;
57
- var subs = [ '^ ! ' ,
58
- ' ^ ! ' ,
71
+ var subs = [ '^ ! ' ,
72
+ ' ^ ! ' ,
59
73
' ^ !' ] ;
60
74
var expected = '--a--b----a--b----a--b--#' ;
61
75
@@ -81,7 +95,7 @@ describe('Observable.prototype.catch()', function () {
81
95
it ( 'should catch and allow the hot observable to proceed with the third ' +
82
96
'(caught) argument' , function ( ) {
83
97
var e1 = hot ( '--a--b--c----d---|' ) ;
84
- var subs = [ '^ ! ' ,
98
+ var subs = [ '^ ! ' ,
85
99
' ^ !' ] ;
86
100
var expected = '--a--b-------d---|' ;
87
101
@@ -132,41 +146,44 @@ describe('Observable.prototype.catch()', function () {
132
146
133
147
it ( 'should complete if you return Observable.empty()' , function ( ) {
134
148
var e1 = hot ( '--a--b--#' ) ;
135
- var subs = '^ !' ;
149
+ var e1subs = '^ !' ;
150
+ var e2 = cold ( '|' ) ;
151
+ var e2subs = ' (^!)' ;
136
152
var expected = '--a--b--|' ;
137
153
138
- var result = e1 . catch ( function ( err ) {
139
- return Observable . empty ( ) ;
140
- } ) ;
154
+ var result = e1 . catch ( function ( ) { return e2 ; } ) ;
141
155
142
156
expectObservable ( result ) . toBe ( expected ) ;
143
- expectSubscriptions ( e1 . subscriptions ) . toBe ( subs ) ;
157
+ expectSubscriptions ( e1 . subscriptions ) . toBe ( e1subs ) ;
158
+ expectSubscriptions ( e2 . subscriptions ) . toBe ( e2subs ) ;
144
159
} ) ;
145
160
146
161
it ( 'should raise error if you return Observable.throw()' , function ( ) {
147
162
var e1 = hot ( '--a--b--#' ) ;
148
- var subs = '^ !' ;
163
+ var e1subs = '^ !' ;
164
+ var e2 = cold ( '#' ) ;
165
+ var e2subs = ' (^!)' ;
149
166
var expected = '--a--b--#' ;
150
167
151
- var result = e1 . catch ( function ( err ) {
152
- return Observable . throw ( 'error' ) ;
153
- } ) ;
168
+ var result = e1 . catch ( function ( ) { return e2 ; } ) ;
154
169
155
170
expectObservable ( result ) . toBe ( expected ) ;
156
- expectSubscriptions ( e1 . subscriptions ) . toBe ( subs ) ;
171
+ expectSubscriptions ( e1 . subscriptions ) . toBe ( e1subs ) ;
172
+ expectSubscriptions ( e2 . subscriptions ) . toBe ( e2subs ) ;
157
173
} ) ;
158
174
159
175
it ( 'should never terminate if you return Observable.never()' , function ( ) {
160
176
var e1 = hot ( '--a--b--#' ) ;
161
- var subs = '^ ' ;
177
+ var e1subs = '^ !' ;
178
+ var e2 = cold ( '-' ) ;
179
+ var e2subs = ' ^' ;
162
180
var expected = '--a--b---' ;
163
181
164
- var result = e1 . catch ( function ( err ) {
165
- return Observable . never ( ) ;
166
- } ) ;
182
+ var result = e1 . catch ( function ( ) { return e2 ; } ) ;
167
183
168
184
expectObservable ( result ) . toBe ( expected ) ;
169
- expectSubscriptions ( e1 . subscriptions ) . toBe ( subs ) ;
185
+ expectSubscriptions ( e1 . subscriptions ) . toBe ( e1subs ) ;
186
+ expectSubscriptions ( e2 . subscriptions ) . toBe ( e2subs ) ;
170
187
} ) ;
171
188
172
189
it ( 'should pass the error as the first argument' , function ( done ) {
0 commit comments