@@ -95,4 +95,107 @@ describe('count', function () {
95
95
96
96
expectObservable ( e1 . count ( ) ) . toBe ( expected , null , new Error ( 'too bad' ) ) ;
97
97
} ) ;
98
+
99
+ it ( 'should handle an always-true predicate on an empty hot observable' , function ( ) {
100
+ var e1 = hot ( '-x-^---|' ) ;
101
+ var expected = '----(w|)' ;
102
+ var predicate = function ( ) {
103
+ return true ;
104
+ } ;
105
+
106
+ expectObservable ( e1 . count ( predicate ) ) . toBe ( expected , { w : 0 } ) ;
107
+ } ) ;
108
+
109
+ it ( 'should handle an always-false predicate on an empty hot observable' , function ( ) {
110
+ var e1 = hot ( '-x-^---|' ) ;
111
+ var expected = '----(w|)' ;
112
+ var predicate = function ( ) {
113
+ return false ;
114
+ } ;
115
+
116
+ expectObservable ( e1 . count ( predicate ) ) . toBe ( expected , { w : 0 } ) ;
117
+ } ) ;
118
+
119
+ it ( 'should handle an always-true predicate on a simple hot observable' , function ( ) {
120
+ var e1 = hot ( '-x-^-a-|' ) ;
121
+ var expected = '----(w|)' ;
122
+ var predicate = function ( ) {
123
+ return true ;
124
+ } ;
125
+
126
+ expectObservable ( e1 . count ( predicate ) ) . toBe ( expected , { w : 1 } ) ;
127
+ } ) ;
128
+
129
+ it ( 'should handle an always-false predicate on a simple hot observable' , function ( ) {
130
+ var e1 = hot ( '-x-^-a-|' ) ;
131
+ var expected = '----(w|)' ;
132
+ var predicate = function ( ) {
133
+ return false ;
134
+ } ;
135
+
136
+ expectObservable ( e1 . count ( predicate ) ) . toBe ( expected , { w : 0 } ) ;
137
+ } ) ;
138
+
139
+ it ( 'should handle a match-all predicate on observable with many values' , function ( ) {
140
+ var e1 = hot ( '-1-^-2--3--4-|' ) ;
141
+ var expected = '----------(w|)' ;
142
+ var predicate = function ( value ) {
143
+ return parseInt ( value ) < 10 ;
144
+ } ;
145
+
146
+ expectObservable ( e1 . count ( predicate ) ) . toBe ( expected , { w : 3 } ) ;
147
+ } ) ;
148
+
149
+ it ( 'should handle a match-none predicate on observable with many values' , function ( ) {
150
+ var e1 = hot ( '-1-^-2--3--4-|' ) ;
151
+ var expected = '----------(w|)' ;
152
+ var predicate = function ( value ) {
153
+ return parseInt ( value ) > 10 ;
154
+ } ;
155
+
156
+ expectObservable ( e1 . count ( predicate ) ) . toBe ( expected , { w : 0 } ) ;
157
+ } ) ;
158
+
159
+ it ( 'should handle an always-true predicate on observable that throws' , function ( ) {
160
+ var e1 = hot ( '-1-^---#' ) ;
161
+ var expected = '----#' ;
162
+ var predicate = function ( ) {
163
+ return true ;
164
+ } ;
165
+
166
+ expectObservable ( e1 . count ( predicate ) ) . toBe ( expected ) ;
167
+ } ) ;
168
+
169
+ it ( 'should handle an always-false predicate on observable that throws' , function ( ) {
170
+ var e1 = hot ( '-1-^---#' ) ;
171
+ var expected = '----#' ;
172
+ var predicate = function ( ) {
173
+ return false ;
174
+ } ;
175
+
176
+ expectObservable ( e1 . count ( predicate ) ) . toBe ( expected ) ;
177
+ } ) ;
178
+
179
+ it ( 'should handle an always-true predicate on a hot never-observable' , function ( ) {
180
+ var e1 = hot ( '-x-^----' ) ;
181
+ var expected = '-----' ;
182
+ var predicate = function ( ) {
183
+ return true ;
184
+ } ;
185
+
186
+ expectObservable ( e1 . count ( predicate ) ) . toBe ( expected ) ;
187
+ } ) ;
188
+
189
+ it ( 'should handle a predicate that throws, on observable with many values' , function ( ) {
190
+ var e1 = hot ( '-1-^-2--3--|' ) ;
191
+ var expected = '-----#' ;
192
+ var predicate = function ( value ) {
193
+ if ( value === '3' ) {
194
+ throw 'error' ;
195
+ }
196
+ return true ;
197
+ } ;
198
+
199
+ expectObservable ( e1 . count ( predicate ) ) . toBe ( expected ) ;
200
+ } ) ;
98
201
} ) ;
0 commit comments