Commit f5d4bf89 authored by Colin Snover's avatar Colin Snover

Update jQuery.hasData to always return a boolean, with unit tests.

parent 445fdf72
...@@ -22,7 +22,7 @@ jQuery.extend({ ...@@ -22,7 +22,7 @@ jQuery.extend({
}, },
hasData: function( elem ) { hasData: function( elem ) {
return !elem.nodeType || (elem[ jQuery.expando ] && !jQuery.isEmptyObject(jQuery.cache[ elem[jQuery.expando] ])); return !elem.nodeType || (!!elem[ jQuery.expando ] && !jQuery.isEmptyObject(jQuery.cache[ elem[jQuery.expando] ]));
}, },
data: function( elem, name, data ) { data: function( elem, name, data ) {
......
...@@ -78,6 +78,15 @@ test("jQuery.data", function() { ...@@ -78,6 +78,15 @@ test("jQuery.data", function() {
ok( jQuery.data( window, "BAD" ), "Make sure that the value was set." ); ok( jQuery.data( window, "BAD" ), "Make sure that the value was set." );
}); });
test("jQuery.hasData", function() {
var div = document.createElement( "div" );
equals( jQuery.hasData(div), false, "No data exists" );
jQuery.data( div, "foo", "bar" );
equals( jQuery.hasData(div), true, "Data exists" );
jQuery.removeData( div, "foo" );
equals( jQuery.hasData(div), false, "Data was removed" );
});
test(".data()", function() { test(".data()", function() {
expect(5); expect(5);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment