Skip to content

Commit 4b918ee

Browse files
authored
Add files via upload
1 parent 65d6234 commit 4b918ee

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

test/unit/manipulation.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3099,3 +3099,66 @@ testIframe(
30993099
} );
31003100
}
31013101
);
3102+
3103+
3104+
// new test cases
3105+
3106+
function nodeName( elem, name ) {
3107+
return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
3108+
}
3109+
3110+
function getAll( context, tag ) {
3111+
3112+
// Support: IE <=9 - 11+
3113+
// Use typeof to avoid zero-argument method invocation on host objects (trac-15151)
3114+
var ret;
3115+
3116+
if ( typeof context.querySelectorAll !== "undefined" ) {
3117+
ret = context.querySelectorAll( tag || "*" );
3118+
3119+
} else {
3120+
ret = [];
3121+
}
3122+
3123+
if ( tag === undefined || tag && nodeName( context, tag ) ) {
3124+
return jQuery.merge( [ context ], ret );
3125+
}
3126+
3127+
return ret;
3128+
}
3129+
3130+
QUnit.test( "should retrieve all elements with a specific tag", function( assert ) {
3131+
assert.expect( 1 );
3132+
var context = document.createElement( "div" );
3133+
context.innerHTML = "<span></span><span></span>";
3134+
3135+
var result = getAll( context, "span" );
3136+
assert.equal( result.length, 2, "Found two span elements" );
3137+
} );
3138+
3139+
QUnit.test( "should retrieve all elements if no tag is specified", function( assert ) {
3140+
assert.expect( 1 );
3141+
var context = document.createElement( "div" );
3142+
context.innerHTML = "<span></span><span></span>";
3143+
3144+
var result = getAll( context );
3145+
assert.equal( result.length, 3, "Found three elements including the context itself" );
3146+
} );
3147+
3148+
QUnit.test( "should retrieve elements including the context if it matches the tag", function( assert ) {
3149+
assert.expect( 1 );
3150+
var context = document.createElement( "div" );
3151+
context.innerHTML = "<div></div><span></span>";
3152+
3153+
var result = getAll( context, "div" );
3154+
assert.equal( result.length, 2, "Found two div elements including the context itself" );
3155+
} );
3156+
3157+
QUnit.test( "should return an empty array if no matching elements are found", function( assert ) {
3158+
assert.expect( 1 );
3159+
var context = document.createElement( "div" );
3160+
context.innerHTML = "<span></span><span></span>";
3161+
3162+
var result = getAll( context, "p" );
3163+
assert.equal( result.length, 0, "Found no p elements" );
3164+
} );

0 commit comments

Comments
 (0)