From 5dc4616ca0fdbf2a80890bd9b236e796b84db8c1 Mon Sep 17 00:00:00 2001 From: Timmy Willison Date: Mon, 16 Mar 2015 11:52:05 -0400 Subject: [PATCH] Attributes: fix failing test for new return value --- src/attributes/attr.js | 2 +- test/unit/attributes.js | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/attributes/attr.js b/src/attributes/attr.js index 3bb05a5a3..201a2d2a6 100644 --- a/src/attributes/attr.js +++ b/src/attributes/attr.js @@ -28,7 +28,7 @@ jQuery.extend({ // don't get/set attributes on text, comment and attribute nodes if ( !elem || nType === 3 || nType === 8 || nType === 2 ) { - return; + return null; } // Fallback to prop when attributes are not supported diff --git a/test/unit/attributes.js b/test/unit/attributes.js index c4bd17c17..1163ff4e1 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -377,8 +377,17 @@ test( "attr(String, Object)", function() { jQuery.each( [ window, document, obj, "#firstp" ], function( i, elem ) { var oldVal = elem.nonexisting, $elem = jQuery( elem ); - strictEqual( $elem.attr("nonexisting"), null, "attr works correctly for non existing attributes (bug #7500)." ); - equal( $elem.attr( "nonexisting", "foo" ).attr("nonexisting"), "foo", "attr falls back to prop on unsupported arguments" ); + // Falls back to prop, which returns undefined + strictEqual( + $elem.attr( "nonexisting" ), + typeof $elem[0].getAttribute === "undefined" ? undefined : null, + "attr works correctly for non existing attributes (bug #7500)." + ); + equal( + $elem.attr( "nonexisting", "foo" ).attr( "nonexisting" ), + "foo", + "attr falls back to prop on unsupported arguments" + ); elem.nonexisting = oldVal; }); -- 2.39.5