@@ -257,7 +257,7 @@ describe('angular', function() {
257
257
function MyObj ( ) {
258
258
this . bar = 'barVal' ;
259
259
this . baz = 'bazVal' ;
260
- } ;
260
+ }
261
261
MyObj . prototype . foo = 'fooVal' ;
262
262
263
263
var obj = new MyObj ( ) ,
@@ -267,6 +267,77 @@ describe('angular', function() {
267
267
268
268
expect ( log ) . toEqual ( [ 'bar:barVal' , 'baz:bazVal' ] ) ;
269
269
} ) ;
270
+
271
+
272
+ it ( 'should handle JQLite and jQuery objects like arrays' , function ( ) {
273
+ var jqObject = jqLite ( "<p><span>s1</span><span>s2</span></p>" ) . find ( "span" ) ,
274
+ log = [ ] ;
275
+
276
+ forEach ( jqObject , function ( value , key ) { log . push ( key + ':' + value . innerHTML ) } ) ;
277
+ expect ( log ) . toEqual ( [ '0:s1' , '1:s2' ] ) ;
278
+ } ) ;
279
+
280
+
281
+ it ( 'should handle NodeList objects like arrays' , function ( ) {
282
+ var nodeList = jqLite ( "<p><span>a</span><span>b</span><span>c</span></p>" ) [ 0 ] . childNodes ,
283
+ log = [ ] ;
284
+
285
+
286
+ forEach ( nodeList , function ( value , key ) { log . push ( key + ':' + value . innerHTML ) } ) ;
287
+ expect ( log ) . toEqual ( [ '0:a' , '1:b' , '2:c' ] ) ;
288
+ } ) ;
289
+
290
+
291
+ it ( 'should handle HTMLCollection objects like arrays' , function ( ) {
292
+ document . body . innerHTML = "<p>" +
293
+ "<a name='x'>a</a>" +
294
+ "<a name='y'>b</a>" +
295
+ "<a name='x'>c</a>" +
296
+ "</p>" ;
297
+
298
+ var htmlCollection = document . getElementsByName ( 'x' ) ,
299
+ log = [ ] ;
300
+
301
+ forEach ( htmlCollection , function ( value , key ) { log . push ( key + ':' + value . innerHTML ) } ) ;
302
+ expect ( log ) . toEqual ( [ '0:a' , '1:c' ] ) ;
303
+ } ) ;
304
+
305
+
306
+ it ( 'should handle arguments objects like arrays' , function ( ) {
307
+ var args ,
308
+ log = [ ] ;
309
+
310
+ ( function ( ) { args = arguments } ( 'a' , 'b' , 'c' ) ) ;
311
+
312
+ forEach ( args , function ( value , key ) { log . push ( key + ':' + value ) } ) ;
313
+ expect ( log ) . toEqual ( [ '0:a' , '1:b' , '2:c' ] ) ;
314
+ } ) ;
315
+
316
+
317
+ it ( 'should handle objects with length property as objects' , function ( ) {
318
+ var obj = {
319
+ 'foo' : 'bar' ,
320
+ 'length' : 2
321
+ } ,
322
+ log = [ ] ;
323
+
324
+ forEach ( obj , function ( value , key ) { log . push ( key + ':' + value ) } ) ;
325
+ expect ( log ) . toEqual ( [ 'foo:bar' , 'length:2' ] ) ;
326
+ } ) ;
327
+
328
+
329
+ it ( 'should handle objects of custom types with length property as objects' , function ( ) {
330
+ function CustomType ( ) {
331
+ this . length = 2 ;
332
+ this . foo = 'bar'
333
+ }
334
+
335
+ var obj = new CustomType ( ) ,
336
+ log = [ ] ;
337
+
338
+ forEach ( obj , function ( value , key ) { log . push ( key + ':' + value ) } ) ;
339
+ expect ( log ) . toEqual ( [ 'length:2' , 'foo:bar' ] ) ;
340
+ } ) ;
270
341
} ) ;
271
342
272
343
0 commit comments