aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/unit/core/core.js4
-rw-r--r--ui/labels.js4
2 files changed, 7 insertions, 1 deletions
diff --git a/tests/unit/core/core.js b/tests/unit/core/core.js
index 770ea4138..b5b6b3b81 100644
--- a/tests/unit/core/core.js
+++ b/tests/unit/core/core.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() {
diff --git a/ui/labels.js b/ui/labels.js
index 2a78d886b..1bf56ac41 100644
--- a/ui/labels.js
+++ b/ui/labels.js
@@ -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 );