@@ -1048,6 +1048,36 @@ describe("Directory", () => {
10481048 assert . equal ( directory2 . get ( "testKey2" ) , undefined ) ;
10491049 } ) ;
10501050
1051+ it ( ".forEach() should iterate over all keys in the directory" , ( ) => {
1052+ const values = [
1053+ [ "a" , "b" ] ,
1054+ [ "c" , "d" ] ,
1055+ [ "e" , "f" ] ,
1056+ ] ;
1057+
1058+ for ( const [ key , value ] of values ) {
1059+ directory1 . set ( key , value ) ;
1060+ }
1061+ containerRuntimeFactory . processAllMessages ( ) ;
1062+
1063+ let i = 0 ;
1064+ // eslint-disable-next-line unicorn/no-array-for-each
1065+ directory1 . forEach ( ( value , key ) => {
1066+ assert ( i < values . length , "forEach() should not have iterated more than i times" ) ;
1067+ assert . strictEqual ( key , values [ i ] [ 0 ] , "key should match" ) ;
1068+ assert . strictEqual ( value , values [ i ] [ 1 ] , "value should match" ) ;
1069+ i ++ ;
1070+ } ) ;
1071+ i = 0 ;
1072+ // eslint-disable-next-line unicorn/no-array-for-each
1073+ directory2 . forEach ( ( value , key ) => {
1074+ assert ( i < values . length , "forEach() should not have iterated more than i times" ) ;
1075+ assert . strictEqual ( key , values [ i ] [ 0 ] , "key should match" ) ;
1076+ assert . strictEqual ( value , values [ i ] [ 1 ] , "value should match" ) ;
1077+ i ++ ;
1078+ } ) ;
1079+ } ) ;
1080+
10511081 it ( "Shouldn't clear value if there is pending set" , ( ) => {
10521082 const valuesChanged : IDirectoryValueChanged [ ] = [ ] ;
10531083 let clearCount = 0 ;
0 commit comments