@@ -31,6 +31,11 @@ describe("Empty map", () => {
3131it ( "Empty map entries returns empty array" , ( ) => {
3232assert ( [ ...arrayStringMap . entries ( ) ] . length === 0 ) ;
3333} )
34+ it ( "Empty map forEach" , ( ) => {
35+ arrayStringMap . forEach ( ( ) => {
36+ assert ( false , "forEach should not be called" ) ;
37+ } ) ;
38+ } )
3439} )
3540
3641describe ( "Map with one object" , ( ) => {
@@ -97,6 +102,16 @@ describe("Map with one object", () => {
97102// works as expected
98103assert ( copiedMap . _converterInfo . size === 0 , "Converter map size is 0" ) ;
99104} )
105+ it ( "Map forEach is called once" , ( ) => {
106+ let count = 0 ;
107+ arrayStringMap . forEach ( ( value , key , map ) => {
108+ count ++ ;
109+ assert ( value === sampleValue1 , "Value is sampleValue1" ) ;
110+ assert ( key === sampleArray1 , "Key is sampleArray1" ) ;
111+ assert ( map === arrayStringMap , "Map is arrayStringMap" ) ;
112+ } ) ;
113+ assert ( count === 1 , "ForEach is called once" ) ;
114+ } )
100115} )
101116
102117describe ( "Map with one object and different separator" , ( ) => {
@@ -138,6 +153,16 @@ describe("Map with one object and alternate array", () => {
138153assert ( [ ...arrayStringMap . values ( ) ] . length === 1 , "Array length is 1" ) ;
139154assert ( [ ...arrayStringMap . values ( ) ] [ 0 ] === sampleValue2 , "Value is sampleValue2" ) ;
140155} )
156+ it ( "Map forEach is called once" , ( ) => {
157+ let count = 0 ;
158+ arrayStringMap . forEach ( ( value , key , map ) => {
159+ count ++ ;
160+ assert ( value === sampleValue2 , "Value is sampleValue2" ) ;
161+ assert ( key === sampleArray2 , "Key is sampleArray2" ) ;
162+ assert ( map === arrayStringMap , "Map is arrayStringMap" ) ;
163+ } ) ;
164+ assert ( count === 1 , "ForEach is called once" ) ;
165+ } )
141166} )
142167
143168describe ( "Map with two objects" , ( ) => {
@@ -222,4 +247,20 @@ describe("Map with two objects", () => {
222247// works as expected
223248assert ( copiedMap . _converterInfo . size === 1 , "Converter map size is 1" ) ;
224249} )
250+ it ( "Map forEach is called twice" , ( ) => {
251+ let count = 0 ;
252+ arrayStringMap . forEach ( ( value , key , map ) => {
253+ count ++ ;
254+ assert ( map === arrayStringMap , "Map is arrayStringMap" ) ;
255+ if ( count === 0 ) {
256+ assert ( key === sampleArray1 , "Key is sampleArray1" ) ;
257+ assert ( value === sampleValue1 , "Value is sampleValue1" ) ;
258+ }
259+ else if ( count === 1 ) {
260+ assert ( key === sampleArray3 , "Key is sampleArray3" ) ;
261+ assert ( value === sampleValue2 , "Value is sampleValue2" ) ;
262+ }
263+ } ) ;
264+ assert ( count === 2 , "ForEach is called twice" ) ;
265+ } )
225266} )