Skip to content
Permalink
Browse files

Tests: Added several more property checks to domEqual().

  • Loading branch information...
scottgonzalez committed May 25, 2012
1 parent be784b2 commit 3b7c33fd496d8db82a71158f3663d52e3dc3c4ac
Showing with 39 additions and 15 deletions.
  1. +39 −15 tests/unit/testsuite.js
@@ -138,32 +138,56 @@ TestHelpers.commonWidgetTests = function( widget, settings ) {
/*
* Experimental assertion for comparing DOM objects.
*
* Serializes an element and some attributes and it's children if any, otherwise the text.
* Serializes an element and some properties and it's children if any, otherwise the text.
* Then compares the result using deepEqual.
*/
window.domEqual = function( selector, modifier, message ) {
var expected, actual,
attributes = ["class", "role", "id", "tabIndex", "aria-activedescendant"];

function extract(value) {
if (!value || !value.length) {
QUnit.push( false, actual, expected, "domEqual failed, can't extract " + selector + ", message was: " + message );
properties = [
"autocomplete",
"aria-activedescendant",
"aria-controls",
"aria-describedby",
"aria-disabled",
"aria-expanded",
"aria-haspopup",
"aria-hidden",
"aria-labelledby",
"aria-pressed",
"aria-selected",
"aria-valuemax",
"aria-valuemin",
"aria-valuenow",
"class",
"disabled",
"href",
"id",
"nodeName",
"readOnly",
"role",
"tabIndex",
"title"
];

function extract( elem ) {
if ( !elem || !elem.length ) {
QUnit.push( false, actual, expected,
"domEqual failed, can't extract " + selector + ", message was: " + message );
return;
}

var children,
result = {};
result.nodeName = value[0].nodeName;
$.each(attributes, function(index, attr) {
result[attr] = value.prop(attr);
$.each( properties, function( index, attr ) {
result[ attr ] = elem.prop( attr );
});
result.children = [];
children = value.children();
if (children.length) {
children.each(function() {
result.children.push(extract($(this)));
children = elem.children();
if ( children.length ) {
result.children = elem.children().map(function( ind ) {
return extract( $( this ) );
});
} else {
result.text = value.text();
result.text = elem.text();
}
return result;
}

0 comments on commit 3b7c33f

Please sign in to comment.
You can’t perform that action at this time.