Refactored unittest.js so that it does not rely on Selector methods. (Easier to debug Selector test failures.)

This commit is contained in:
Andrew Dupont 2008-03-31 12:07:46 -05:00
parent d13a93882c
commit ee52460014
2 changed files with 20 additions and 12 deletions

View File

@ -86,15 +86,17 @@ Test.Unit.Logger = Class.create({
initialize: function(element) {
this.element = $(element);
if (this.element) this._createLogTable();
this.tbody = $(this.element.getElementsByTagName('tbody')[0]);
},
start: function(testName) {
if (!this.element) return;
this.element.down('tbody').insert('<tr><td>' + testName + '</td><td></td><td></td></tr>');
this.tbody.insert('<tr><td>' + testName + '</td><td></td><td></td></tr>');
},
setStatus: function(status) {
this.getLastLogLine().addClassName(status).down('td', 1).update(status);
this.getLastLogLine().addClassName(status);
$(this.getLastLogLine().getElementsByTagName('td')[1]).update(status);
},
finish: function(status, summary) {
@ -110,15 +112,18 @@ Test.Unit.Logger = Class.create({
summary: function(summary) {
if (!this.element) return;
this.element.down('div').update(this._toHTML(summary));
var div = $(this.element.getElementsByTagName('div')[0]);
div.update(this._toHTML(summary));
},
getLastLogLine: function() {
return this.element.select('tr').last()
var trs = this.element.getElementsByTagName('tr');
return $(trs[trs.length - 1]);
},
getMessageCell: function() {
return this.getLastLogLine().down('td', 2);
var tds = this.getLastLogLine().getElementsByTagName('td');
return $(tds[2]);
},
_createLogTable: function() {
@ -144,7 +149,7 @@ Test.Unit.Logger = Class.create({
},
_toHTML: function(txt) {
return txt.escapeHTML().replace(/\n/g,"<br/>");
return txt.escapeHTML().replace(/\n/g,"<br />");
}
});

View File

@ -167,8 +167,8 @@
},
testSelectorWithTagNameAndWhitespaceTokenizedAttributeValue: function() {
this.assertEnumEqual($('link_1', 'link_2'), $$('a[class~="internal"]'));
this.assertEnumEqual($('link_1', 'link_2'), $$('a[class~=internal]'));
this.assertEnumEqual($('link_1', 'link_2'), $$('a[class~="internal"]'), "a[class~=\"internal\"]");
this.assertEnumEqual($('link_1', 'link_2'), $$('a[class~=internal]'), "a[class~=internal]");
},
testSelectorWithAttributeAndNoTagName: function() {
@ -199,12 +199,14 @@
},
test$$WithNestedAttributeSelectors: function() {
this.assertEnumEqual([$('strong')], $$('div[style] p[id] strong'));
this.assertEnumEqual([$('strong')], $$('div[style] p[id] strong'), 'div[style] p[id] strong');
},
testSelectorWithMultipleConditions: function() {
this.assertEnumEqual([$('link_3')], $$('a[class~=external][href="#"]'));
this.assertEnumEqual([], $$('a[class~=external][href!="#"]'));
this.assertEnumEqual([$('link_3')], $$('a[class~=external][href="#"]'),
'a[class~=external][href="#"]');
this.assertEnumEqual([], $$('a[class~=external][href!="#"]'),
'a[class~=external][href!="#"]');
},
testSelectorMatchElements: function() {
@ -393,7 +395,8 @@
testSelectorWithEmpty: function() {
$('level3_1').innerHTML = "";
this.assertEnumEqual($('level3_1', 'level3_2', 'level2_3'), $$('#level1 *:empty'));
this.assertEnumEqual($('level3_1', 'level3_2', 'level2_3'),
$$('#level1 *:empty'), '#level1 *:empty');
this.assertEnumEqual([], $$('#level_only_child:empty'), 'newlines count as content!');
},