Skip to content

Commit

Permalink
Return undefined in .prop if given an invalid element or tag (#880)
Browse files Browse the repository at this point in the history
  • Loading branch information
elias-winberg authored and fb55 committed Jul 4, 2016
1 parent df55c93 commit 1d2e8a7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/api/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ exports.attr = function(name, value) {
};

var getProp = function (el, name) {
if (!el || !isTag(el)) return;

return el.hasOwnProperty(name)
? el[name]
: rboolean.test(name)
Expand Down
5 changes: 5 additions & 0 deletions test/api/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ describe('$(...)', function() {
it('(key, value) : should support chaining after setting props', function() {
expect(checkbox.prop('checked', false)).to.equal(checkbox);
});

it('(invalid element/tag) : prop should return undefined', function() {
expect($(undefined).prop('prop')).to.be(undefined);
expect($(null).prop('prop')).to.be(undefined);
});
});

describe('.data', function() {
Expand Down

0 comments on commit 1d2e8a7

Please sign in to comment.