aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/core.js
diff options
context:
space:
mode:
authorMichał Gołębiowski <m.goleb@gmail.com>2015-06-01 23:25:38 +0200
committerMichał Gołębiowski <m.goleb@gmail.com>2015-06-13 23:31:27 +0200
commit2fa3bac7eb2021361a1d0c498c278df812ec48b9 (patch)
treecd425cda15a3a796cda7aa6f7a402487cd6562da /test/unit/core.js
parenta022da70568119688445708970bec1346c9d4217 (diff)
downloadjquery-2fa3bac7eb2021361a1d0c498c278df812ec48b9.tar.gz
jquery-2fa3bac7eb2021361a1d0c498c278df812ec48b9.zip
Core: Make jQuery objects iterable
Make iterating over jQuery objects possible using ES 2015 for-of: for ( node of $( "<div id=narwhal>" ) ) { console.log( node.id ); // "narwhal" } (partially cherry-picked from bb026fc12c3c2ad37f47f0919e484bddcdc3d291) Fixes gh-1693
Diffstat (limited to 'test/unit/core.js')
-rw-r--r--test/unit/core.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/unit/core.js b/test/unit/core.js
index 39e61fcb6..07019e86b 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -1519,3 +1519,23 @@ testIframeWithCallback( "Don't call window.onready (#14802)", "core/onready.html
equal( error, false, "no call to user-defined onready" );
}
);
+
+test( "Iterability of jQuery objects (gh-1693)", function() {
+ /* jshint unused: false */
+ expect( 1 );
+
+ var i, elem, result;
+
+ if ( typeof Symbol === "function" ) {
+
+ elem = jQuery( "<div></div><span></span><a></a>" );
+ result = "";
+
+ try {
+ eval( "for ( i of elem ) { result += i.nodeName; }" );
+ } catch ( e ) {}
+ equal( result, "DIVSPANA", "for-of works on jQuery objects" );
+ } else {
+ ok( true, "The browser doesn't support Symbols" );
+ }
+} );