Skip to content
Permalink
Browse files

Labels: Handle empty sets

Fixes #15184
  • Loading branch information
scottgonzalez committed May 2, 2017
1 parent 0d25a36 commit adcf9b6f6ef9c6dfa88932b40307f581e65bc667
Showing with 7 additions and 1 deletion.
  1. +3 −1 tests/unit/core/core.js
  2. +4 −0 ui/labels.js
@@ -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() {
@@ -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 );

0 comments on commit adcf9b6

Please sign in to comment.
You can’t perform that action at this time.