Skip to content

Commit afdb2c0

Browse files
Add some messages to test assertions in dom_test.js.
1 parent c21b319 commit afdb2c0

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

test/unit/dom_test.js

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -502,12 +502,17 @@ new Test.Unit.Runner({
502502

503503
testElementIdentify: function() {
504504
var parent = $('identification');
505-
this.assertEqual(parent.down().identify(), 'predefined_id');
506-
this.assert(parent.down(1).identify().startsWith('anonymous_element_'));
507-
this.assert(parent.down(2).identify().startsWith('anonymous_element_'));
508-
this.assert(parent.down(3).identify().startsWith('anonymous_element_'));
509-
510-
this.assert(parent.down(3).id !== parent.down(2).id);
505+
this.assertEqual(parent.down().identify(), 'predefined_id',
506+
"identify should preserve the IDs of elements that already have them");
507+
this.assert(parent.down(1).identify().startsWith('anonymous_element_'),
508+
"should have #anonymous_element_1");
509+
this.assert(parent.down(2).identify().startsWith('anonymous_element_'),
510+
"should have #anonymous_element_2");
511+
this.assert(parent.down(3).identify().startsWith('anonymous_element_'),
512+
"should have #anonymous_element_3");
513+
514+
this.assert(parent.down(3).id !== parent.down(2).id,
515+
"should not assign duplicate IDs");
511516
},
512517

513518
testElementClassNameMethod: function() {
@@ -760,10 +765,12 @@ new Test.Unit.Runner({
760765
},
761766

762767
testDescendantOf: function() {
763-
this.assert($('child').descendantOf('ancestor'));
764-
this.assert($('child').descendantOf($('ancestor')));
765-
766-
this.assert(!$('ancestor').descendantOf($('child')));
768+
this.assert($('child').descendantOf('ancestor'),
769+
'#child should be descendant of #ancestor');
770+
this.assert($('child').descendantOf($('ancestor')),
771+
'#child should be descendant of #ancestor');
772+
this.assert(!$('ancestor').descendantOf($('child')),
773+
'#ancestor should not be descendant of child');
767774

768775
this.assert($('great-grand-child').descendantOf('ancestor'), 'great-grand-child < ancestor');
769776
this.assert($('grand-child').descendantOf('ancestor'), 'grand-child < ancestor');
@@ -783,18 +790,23 @@ new Test.Unit.Runner({
783790
this.assert(!$('great-grand-child').descendantOf('not-in-the-family'), 'great-grand-child < not-in-the-family');
784791
this.assert(!$('child').descendantOf('not-in-the-family'), 'child < not-in-the-family');
785792

786-
this.assert(!$(document.body).descendantOf('great-grand-child'));
793+
this.assert(!$(document.body).descendantOf('great-grand-child'),
794+
'BODY should not be descendant of anything within it');
787795

788796
// dynamically-created elements
789797
$('ancestor').insert(new Element('div', { id: 'weird-uncle' }));
790-
this.assert($('weird-uncle').descendantOf('ancestor'));
798+
this.assert($('weird-uncle').descendantOf('ancestor'),
799+
'dynamically-created element should work properly');
791800

792801
$(document.body).insert(new Element('div', { id: 'impostor' }));
793-
this.assert(!$('impostor').descendantOf('ancestor'));
802+
this.assert(!$('impostor').descendantOf('ancestor'),
803+
'elements inserted elsewhere in the DOM tree should not be descendants');
794804

795805
// test descendantOf document
796-
this.assert($(document.body).descendantOf(document));
797-
this.assert($(document.documentElement).descendantOf(document));
806+
this.assert($(document.body).descendantOf(document),
807+
'descendantOf(document) should behave predictably');
808+
this.assert($(document.documentElement).descendantOf(document),
809+
'descendantOf(document) should behave predictably');
798810
},
799811

800812
testChildOf: function() {
@@ -829,11 +841,9 @@ new Test.Unit.Runner({
829841
$('style_test_3').setStyle({ opacity: 0.5 });
830842
this.assertEqual(0.5, $('style_test_3').getStyle('opacity'));
831843

832-
window.debug = true;
833844
$('style_test_3').setStyle({ opacity: '' });
834845
this.assertEqual(1, $('style_test_3').getStyle('opacity'),
835846
'#style_test_3 opacity should be 1');
836-
window.debug = false;
837847

838848
$('style_test_3').setStyle({ opacity: 0 });
839849
this.assertEqual(0, $('style_test_3').getStyle('opacity'),
@@ -869,15 +879,18 @@ new Test.Unit.Runner({
869879
},
870880

871881
testElementSetOpacity: function() {
872-
[0,0.1,0.5,0.999].each(function(opacity){
882+
[0, 0.1, 0.5, 0.999].each(function(opacity){
873883
$('style_test_3').setOpacity(opacity);
874884

875885
// b/c of rounding issues on IE special case
876886
var realOpacity = $('style_test_3').getStyle('opacity');
877887

878888
// opera rounds off to two significant digits, so we check for a
879889
// ballpark figure
880-
this.assert((Number(realOpacity) - opacity) <= 0.002, 'setting opacity to ' + opacity);
890+
this.assert(
891+
(Number(realOpacity) - opacity) <= 0.002,
892+
'setting opacity to ' + opacity + ' (actual: ' + realOpacity + ')'
893+
);
881894
}, this);
882895

883896
this.assertEqual(0,

0 commit comments

Comments
 (0)