aboutsummaryrefslogtreecommitdiffstats
path: root/test/node_smoke_tests
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:14:36 +0200
commitbb026fc12c3c2ad37f47f0919e484bddcdc3d291 (patch)
tree7ba8975dcfd6c912f8ecb71761648ad4a38efe9b /test/node_smoke_tests
parent9c8a3ecdc46156afd8f93aa44b6e6aea7c52c049 (diff)
downloadjquery-bb026fc12c3c2ad37f47f0919e484bddcdc3d291.tar.gz
jquery-bb026fc12c3c2ad37f47f0919e484bddcdc3d291.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" } Fixes gh-1693
Diffstat (limited to 'test/node_smoke_tests')
-rw-r--r--test/node_smoke_tests/iterable_with_native_symbol.js8
-rw-r--r--test/node_smoke_tests/iterable_with_symbol_polyfill.js13
-rw-r--r--test/node_smoke_tests/lib/ensure_iterability_es6.js25
3 files changed, 46 insertions, 0 deletions
diff --git a/test/node_smoke_tests/iterable_with_native_symbol.js b/test/node_smoke_tests/iterable_with_native_symbol.js
new file mode 100644
index 000000000..3376ebdc5
--- /dev/null
+++ b/test/node_smoke_tests/iterable_with_native_symbol.js
@@ -0,0 +1,8 @@
+"use strict";
+
+if ( typeof Symbol === "undefined" ) {
+ console.log( "Symbols not supported, skipping the test..." );
+ process.exit();
+}
+
+require( "./lib/ensure_iterability_es6" )();
diff --git a/test/node_smoke_tests/iterable_with_symbol_polyfill.js b/test/node_smoke_tests/iterable_with_symbol_polyfill.js
new file mode 100644
index 000000000..dd377f19c
--- /dev/null
+++ b/test/node_smoke_tests/iterable_with_symbol_polyfill.js
@@ -0,0 +1,13 @@
+/* jshint esnext: true */
+
+"use strict";
+
+var assert = require( "assert" );
+
+delete global.Symbol;
+require( "core-js" );
+
+assert.strictEqual( typeof Symbol, "function", "Expected Symbol to be a function" );
+assert.notEqual( typeof Symbol.iterator, "symbol", "Expected Symbol.iterator to be polyfilled" );
+
+require( "./lib/ensure_iterability" )();
diff --git a/test/node_smoke_tests/lib/ensure_iterability_es6.js b/test/node_smoke_tests/lib/ensure_iterability_es6.js
new file mode 100644
index 000000000..ebe68539e
--- /dev/null
+++ b/test/node_smoke_tests/lib/ensure_iterability_es6.js
@@ -0,0 +1,25 @@
+/* jshint esnext: true */
+
+"use strict";
+
+var assert = require( "assert" );
+
+module.exports = function ensureIterability() {
+ require( "jsdom" ).env( "", function( errors, window ) {
+ assert.ifError( errors );
+
+ var i,
+ ensureJQuery = require( "./ensure_jquery" ),
+ jQuery = require( "../../../dist/jquery.js" )( window ),
+ elem = jQuery( "<div></div><span></span><a></a>" ),
+ result = "";
+
+ ensureJQuery( jQuery );
+
+ for ( i of elem ) {
+ result += i.nodeName;
+ }
+
+ assert.strictEqual( result, "DIVSPANA", "for-of doesn't work on jQuery objects" );
+ } );
+};