Force Element.Methods.Simulated.hasAttribute() to return a boolean value.

This commit is contained in:
jdalton 2008-05-15 16:32:00 -05:00 committed by Tobie Langel
parent b49c572fa0
commit 1d0fb77ec3
2 changed files with 13 additions and 1 deletions

View File

@ -1028,7 +1028,7 @@ Element.Methods.Simulated = {
hasAttribute: function(element, attribute) {
attribute = Element._attributeTranslations.has[attribute] || attribute;
var node = $(element).getAttributeNode(attribute);
return node && node.specified;
return !!(node && node.specified);
}
};

View File

@ -1002,6 +1002,18 @@ new Test.Unit.Runner({
this.assertEqual('26', p.readAttribute('age'));
},
testElementHasAttribute: function() {
var label = $('write_attribute_label');
this.assertIdentical(true, label.hasAttribute('for'));
this.assertIdentical(false, label.hasAttribute('htmlFor'));
this.assertIdentical(false, label.hasAttribute('className'));
this.assertIdentical(false, label.hasAttribute('rainbows'));
var input = $('write_attribute_input');
this.assertNotIdentical(null, input.hasAttribute('readonly'));
this.assertNotIdentical(null, input.hasAttribute('readOnly'));
},
testNewElement: function() {
this.assert(new Element('h1'));