2015-06-01 21:25:38 +00:00
|
|
|
"use strict";
|
|
|
|
|
2023-07-10 18:45:30 +00:00
|
|
|
const assert = require( "node:assert" );
|
|
|
|
const { JSDOM } = require( "jsdom" );
|
2015-06-01 21:25:38 +00:00
|
|
|
|
2023-07-10 18:45:30 +00:00
|
|
|
const { ensureJQuery } = require( "./ensure_jquery" );
|
2015-06-01 21:25:38 +00:00
|
|
|
|
2023-07-10 18:45:30 +00:00
|
|
|
const ensureIterability = ( jQueryModuleSpecifier ) => {
|
2019-03-04 17:30:51 +00:00
|
|
|
const { window } = new JSDOM( "" );
|
2015-06-01 21:25:38 +00:00
|
|
|
|
2023-07-10 18:45:30 +00:00
|
|
|
const jQueryFactory = require( jQueryModuleSpecifier );
|
|
|
|
const jQuery = jQueryFactory( window );
|
2019-03-04 17:30:51 +00:00
|
|
|
const elem = jQuery( "<div></div><span></span><a></a>" );
|
2015-06-01 21:25:38 +00:00
|
|
|
|
2019-03-04 17:30:51 +00:00
|
|
|
ensureJQuery( jQuery );
|
2015-06-01 21:25:38 +00:00
|
|
|
|
2023-07-10 18:45:30 +00:00
|
|
|
let result = "";
|
|
|
|
for ( const node of elem ) {
|
|
|
|
result += node.nodeName;
|
2019-03-04 17:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert.strictEqual( result, "DIVSPANA", "for-of works on jQuery objects" );
|
2015-06-01 21:25:38 +00:00
|
|
|
};
|
2019-03-04 17:30:51 +00:00
|
|
|
|
2023-07-10 18:45:30 +00:00
|
|
|
module.exports = { ensureIterability };
|