@@ -208,7 +208,7 @@ describe('DeltaSnapshot', () => {
208
208
} ) ;
209
209
} ) ;
210
210
211
- describe ( '#forEach(childAction: Function) ' , ( ) => {
211
+ describe ( '#forEach(action: (a: DeltaSnapshot) => boolean): boolean ' , ( ) => {
212
212
it ( 'should iterate through child snapshots' , ( ) => {
213
213
populate ( { a : 'b' } , { c : 'd' } ) ;
214
214
let out = '' ;
@@ -223,12 +223,46 @@ describe('DeltaSnapshot', () => {
223
223
let count = 0 ;
224
224
let counter = snap => count ++ ;
225
225
226
- subject . forEach ( counter ) ;
226
+ expect ( subject . forEach ( counter ) ) . to . equal ( false ) ;
227
227
populate ( 23 , null ) ;
228
228
229
- subject . forEach ( counter ) ;
229
+ expect ( subject . forEach ( counter ) ) . to . equal ( false ) ;
230
230
expect ( count ) . to . eq ( 0 ) ;
231
231
} ) ;
232
+
233
+ it ( 'should cancel further enumeration if callback returns true' , ( ) => {
234
+ populate ( null , { a : 'b' , c : 'd' , e : 'f' , g : 'h' } ) ;
235
+ let out = '' ;
236
+ const ret = subject . forEach ( snap => {
237
+ if ( snap . val ( ) === 'f' ) {
238
+ return true ;
239
+ }
240
+ out += snap . val ( ) ;
241
+ } ) ;
242
+ expect ( out ) . to . equal ( 'bd' ) ;
243
+ expect ( ret ) . to . equal ( true ) ;
244
+ } ) ;
245
+
246
+ it ( 'should not cancel further enumeration if callback returns a truthy value' , ( ) => {
247
+ populate ( null , { a : 'b' , c : 'd' , e : 'f' , g : 'h' } ) ;
248
+ let out = '' ;
249
+ const ret = subject . forEach ( snap => {
250
+ out += snap . val ( ) ;
251
+ return 1 ;
252
+ } ) ;
253
+ expect ( out ) . to . equal ( 'bdfh' ) ;
254
+ expect ( ret ) . to . equal ( false ) ;
255
+ } ) ;
256
+
257
+ it ( 'should not cancel further enumeration if callback does not return' , ( ) => {
258
+ populate ( null , { a : 'b' , c : 'd' , e : 'f' , g : 'h' } ) ;
259
+ let out = '' ;
260
+ const ret = subject . forEach ( snap => {
261
+ out += snap . val ( ) ;
262
+ } ) ;
263
+ expect ( out ) . to . equal ( 'bdfh' ) ;
264
+ expect ( ret ) . to . equal ( false ) ;
265
+ } ) ;
232
266
} ) ;
233
267
234
268
describe ( '#numChildren()' , ( ) => {
0 commit comments