Labels: Handle empty sets

Fixes #15184
This commit is contained in:
Scott González 2017-05-02 12:42:49 -04:00
parent 0d25a36eec
commit adcf9b6f6e
2 changed files with 7 additions and 1 deletions

View File

@ -142,7 +142,7 @@ QUnit.test( "uniqueId / removeUniqueId", function( assert ) {
} );
QUnit.test( "Labels", function( assert ) {
assert.expect( 2 );
assert.expect( 3 );
var expected = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ];
var dom = $( "#labels-fragment" );
@ -165,6 +165,8 @@ QUnit.test( "Labels", function( assert ) {
// Detach the dom to test on a fragment
dom.detach();
testLabels( "document fragments" );
assert.equal( $().labels().length, 0, "No element" );
} );
( function() {

View File

@ -27,6 +27,10 @@
return $.fn.labels = function() {
var ancestor, selector, id, labels, ancestors;
if ( !this.length ) {
return this.pushStack( [] );
}
// Check control.labels first
if ( this[ 0 ].labels && this[ 0 ].labels.length ) {
return this.pushStack( this[ 0 ].labels );