jquery/test/node_smoke_tests/lib/ensure_iterability_es6.js
Michał Gołębiowski bb026fc12c 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
2015-06-13 23:14:36 +02:00

26 lines
574 B
JavaScript

/* 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" );
} );
};