@@ -208,7 +208,7 @@ describe('DeltaSnapshot', () => {
208208 } ) ;
209209 } ) ;
210210
211- describe ( '#forEach(childAction: Function) ' , ( ) => {
211+ describe ( '#forEach(action: (a: DeltaSnapshot) => boolean): boolean ' , ( ) => {
212212 it ( 'should iterate through child snapshots' , ( ) => {
213213 populate ( { a : 'b' } , { c : 'd' } ) ;
214214 let out = '' ;
@@ -223,12 +223,46 @@ describe('DeltaSnapshot', () => {
223223 let count = 0 ;
224224 let counter = snap => count ++ ;
225225
226- subject . forEach ( counter ) ;
226+ expect ( subject . forEach ( counter ) ) . to . equal ( false ) ;
227227 populate ( 23 , null ) ;
228228
229- subject . forEach ( counter ) ;
229+ expect ( subject . forEach ( counter ) ) . to . equal ( false ) ;
230230 expect ( count ) . to . eq ( 0 ) ;
231231 } ) ;
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+ } ) ;
232266 } ) ;
233267
234268 describe ( '#numChildren()' , ( ) => {
0 commit comments