Skip to content

Commit adcf9b6

Browse files
committed
Labels: Handle empty sets
Fixes #15184
1 parent 0d25a36 commit adcf9b6

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

tests/unit/core/core.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ QUnit.test( "uniqueId / removeUniqueId", function( assert ) {
142142
} );
143143

144144
QUnit.test( "Labels", function( assert ) {
145-
assert.expect( 2 );
145+
assert.expect( 3 );
146146

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

170172
( function() {

ui/labels.js

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
return $.fn.labels = function() {
2828
var ancestor, selector, id, labels, ancestors;
2929

30+
if ( !this.length ) {
31+
return this.pushStack( [] );
32+
}
33+
3034
// Check control.labels first
3135
if ( this[ 0 ].labels && this[ 0 ].labels.length ) {
3236
return this.pushStack( this[ 0 ].labels );

0 commit comments

Comments
 (0)