Permalink
Browse files

Attributes: fix failing test for new return value

  • Loading branch information...
timmywil committed Mar 16, 2015
1 parent afca031 commit 17bd6e9cf94f435807eeb538a47b5e506a01f4cb
Showing with 12 additions and 3 deletions.
  1. +1 −1 src/attributes/attr.js
  2. +11 −2 test/unit/attributes.js
View
@@ -31,7 +31,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;

This comment has been minimized.

Show comment
Hide comment
@gibson042

gibson042 Mar 16, 2015

Member

I disagree with this... null is reasonable from $element.attr( foo ), but not from $nonElement.attr( foo ).

EDIT: and especially not from $().attr( foo ). Related: #2134.

@gibson042

gibson042 Mar 16, 2015

Member

I disagree with this... null is reasonable from $element.attr( foo ), but not from $nonElement.attr( foo ).

EDIT: and especially not from $().attr( foo ). Related: #2134.

}
// Fallback to prop when attributes are not supported
View
@@ -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;
});

0 comments on commit 17bd6e9

Please sign in to comment.