@@ -31,6 +31,11 @@ describe("Empty map", () => {
31
31
it ( "Empty map entries returns empty array" , ( ) => {
32
32
assert ( [ ...arrayStringMap . entries ( ) ] . length === 0 ) ;
33
33
} )
34
+ it ( "Empty map forEach" , ( ) => {
35
+ arrayStringMap . forEach ( ( ) => {
36
+ assert ( false , "forEach should not be called" ) ;
37
+ } ) ;
38
+ } )
34
39
} )
35
40
36
41
describe ( "Map with one object" , ( ) => {
@@ -97,6 +102,16 @@ describe("Map with one object", () => {
97
102
// works as expected
98
103
assert ( copiedMap . _converterInfo . size === 0 , "Converter map size is 0" ) ;
99
104
} )
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
+ } )
100
115
} )
101
116
102
117
describe ( "Map with one object and different separator" , ( ) => {
@@ -138,6 +153,16 @@ describe("Map with one object and alternate array", () => {
138
153
assert ( [ ...arrayStringMap . values ( ) ] . length === 1 , "Array length is 1" ) ;
139
154
assert ( [ ...arrayStringMap . values ( ) ] [ 0 ] === sampleValue2 , "Value is sampleValue2" ) ;
140
155
} )
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
+ } )
141
166
} )
142
167
143
168
describe ( "Map with two objects" , ( ) => {
@@ -222,4 +247,20 @@ describe("Map with two objects", () => {
222
247
// works as expected
223
248
assert ( copiedMap . _converterInfo . size === 1 , "Converter map size is 1" ) ;
224
249
} )
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
+ } )
225
266
} )
0 commit comments