aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/testsuite.js
diff options
context:
space:
mode:
authorjzaefferer <joern.zaefferer@gmail.com>2011-02-25 11:33:48 +0100
committerjzaefferer <joern.zaefferer@gmail.com>2011-02-25 11:33:48 +0100
commit540b78d92026de6e287144b9bf37221699ccb9e8 (patch)
tree78064c3b34c6ac94f4bf8877d8ad823f65e537d3 /tests/unit/testsuite.js
parent6a5eb351c767c3e5879d2cdcd4489b5afa7f03de (diff)
downloadjquery-ui-540b78d92026de6e287144b9bf37221699ccb9e8.tar.gz
jquery-ui-540b78d92026de6e287144b9bf37221699ccb9e8.zip
Adding a domEqual assertion to our testsuite for more sane DOM
comparisons. Comparing innerHTML is too dependent on random browser quirks like IE only sometimes rendering closing tags.
Diffstat (limited to 'tests/unit/testsuite.js')
-rw-r--r--tests/unit/testsuite.js34
1 files changed, 33 insertions, 1 deletions
diff --git a/tests/unit/testsuite.js b/tests/unit/testsuite.js
index b3748d8ee..9c7c46c22 100644
--- a/tests/unit/testsuite.js
+++ b/tests/unit/testsuite.js
@@ -65,6 +65,38 @@ window.commonWidgetTests = function( widget, settings ) {
test( "version", function() {
ok( "version" in $.ui[ widget ], "version property exists" );
});
-};
+}
+
+/*
+ * Experimental assertion for comparing DOM objects.
+ *
+ * Serializes an element and some attributes and it's children if any, otherwise the text.
+ * Then compares the result using deepEqual.
+ */
+window.domEqual = function( selector, modifier, message ) {
+ var attributes = ["class", "role", "id", "tabIndex", "aria-activedescendant"];
+
+ function extract(value) {
+ var result = {};
+ result.nodeName = value[0].nodeName;
+ $.each(attributes, function(index, attr) {
+ result[attr] = value.attr(attr);
+ });
+ result.children = [];
+ var children = value.children();
+ if (children.length) {
+ children.each(function() {
+ result.children.push(extract($(this)));
+ });
+ } else {
+ result.text = value.text();
+ }
+ return result;
+ }
+ var expected = extract($(selector));
+ modifier($(selector));
+
+ deepEqual( extract($(selector)), expected, message );
+}
}());