@@ -167,6 +167,85 @@ describe("core.dom tests", () => {
167167 } ) ;
168168 } ) ;
169169
170+ describe ( "to_element_array tests" , ( ) => {
171+ it ( "returns an array of DOM elements, if a jQuery object was passed." , ( done ) => {
172+ const html = document . createElement ( "div" ) ;
173+ html . innerHTML = `
174+ <span id="id1" />
175+ <span id="id2" />
176+ ` ;
177+ const el1 = html . querySelector ( "#id1" ) ;
178+ const el2 = html . querySelector ( "#id2" ) ;
179+ const testee = $ ( "span" , html ) ;
180+ expect ( testee . length ) . toBe ( 2 ) ;
181+
182+ const ret = dom . to_element_array ( testee ) ;
183+
184+ expect ( ret . jquery ) . toBeFalsy ( ) ;
185+ expect ( ret . length ) . toBe ( 2 ) ;
186+
187+ expect ( ret [ 0 ] ) . toBe ( el1 ) ;
188+ expect ( ret [ 0 ] . jquery ) . toBeFalsy ( ) ;
189+ expect ( ret [ 0 ] instanceof Element ) . toBe ( true ) ;
190+
191+ expect ( ret [ 1 ] ) . toBe ( el2 ) ;
192+ expect ( ret [ 1 ] . jquery ) . toBeFalsy ( ) ;
193+ expect ( ret [ 1 ] instanceof Element ) . toBe ( true ) ;
194+
195+ done ( ) ;
196+ } ) ;
197+
198+ it ( "returns an array of elements, if a NodeList was passed." , ( done ) => {
199+ const html = document . createElement ( "div" ) ;
200+ html . innerHTML = `
201+ <span id="id1" />
202+ <span id="id2" />
203+ ` ;
204+ const el1 = html . querySelector ( "#id1" ) ;
205+ const el2 = html . querySelector ( "#id2" ) ;
206+ const testee = html . querySelectorAll ( "span" ) ;
207+ expect ( testee . length ) . toBe ( 2 ) ;
208+
209+ const ret = dom . to_element_array ( testee ) ;
210+ expect ( ret instanceof NodeList ) . toBeFalsy ( ) ;
211+ expect ( ret . length ) . toBe ( 2 ) ;
212+ expect ( ret [ 0 ] ) . toBe ( el1 ) ;
213+ expect ( ret [ 1 ] ) . toBe ( el2 ) ;
214+
215+ done ( ) ;
216+ } ) ;
217+
218+ it ( "returns an array with a single element, if a single element was passed." , ( done ) => {
219+ const html = document . createElement ( "div" ) ;
220+
221+ const ret = dom . to_element_array ( html ) ;
222+ expect ( ret instanceof Array ) . toBeTruthy ( ) ;
223+ expect ( ret . length ) . toBe ( 1 ) ;
224+ expect ( ret [ 0 ] ) . toBe ( html ) ;
225+
226+ done ( ) ;
227+ } ) ;
228+
229+ it ( "returns an empty array, if nothing was passed" , ( done ) => {
230+ const ret = dom . to_element_array ( ) ;
231+ expect ( ret . length ) . toBe ( 0 ) ;
232+ expect ( ret instanceof Array ) . toBe ( true ) ;
233+
234+ done ( ) ;
235+ } ) ;
236+
237+ it ( "returns only DOM Elements, no Nodes or others" , ( done ) => {
238+ const el = document . body ;
239+ const txt = document . createTextNode ( "okay" ) ;
240+ const ret = dom . to_element_array ( [ 1 , false , txt , "okay" , el ] ) ;
241+ expect ( ret . length ) . toBe ( 1 ) ;
242+ expect ( ret [ 0 ] ) . toBe ( el ) ;
243+
244+ done ( ) ;
245+ } ) ;
246+ } ) ;
247+
248+
170249 describe ( "querySelectorAllAndMe tests" , ( ) => {
171250 it ( "return also starting node if query matches." , ( done ) => {
172251 const el = document . createElement ( "div" ) ;
0 commit comments