@@ -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 = '' ;
@@ -229,6 +229,32 @@ describe('DeltaSnapshot', () => {
229229 subject . forEach ( counter ) ;
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 does not return true' , ( ) => {
247+ populate ( null , { a : 'b' , c : 'd' , e : 'f' , g : 'h' } ) ;
248+ let out = '' ;
249+ const ret = subject . forEach ( snap => {
250+ if ( snap . val ( ) === 'a' ) {
251+ return true ;
252+ }
253+ out += snap . val ( ) ;
254+ } ) ;
255+ expect ( out ) . to . equal ( 'bdfh' ) ;
256+ expect ( ret ) . to . equal ( false ) ;
257+ } ) ;
232258 } ) ;
233259
234260 describe ( '#numChildren()' , ( ) => {
0 commit comments