Permalink
Browse files

New assertions: assertHasClass(element, class)

  • Loading branch information...
1 parent 4aa484e commit b233d98aa47b1f14bf4c1912fe47ef2c9fbfc888 @drnic committed Apr 29, 2008
Showing with 18 additions and 0 deletions.
  1. +2 −0 History.txt
  2. +9 −0 src/assertions.js
  3. +7 −0 test/unit/assertions_test.html
View
@@ -1,3 +1,5 @@
+* New assertions: assertHasClass(element, class)
+
== 0.6.3 2008-03-03
* Remove some innerHTML calls as an IE6 fix [Michael Grosser]
View
@@ -143,7 +143,16 @@ JsUnitTest.Unit.Assertions = {
this.assertBlock(message, function() { return !(new RegExp(expected).exec(actual)) });
},
+ assertHasClass: function(element, class, message) {
+ element = JsUnitTest.$(element);
+ message = this.buildMessage(message || 'assertHasClass', '? doesn\'t have class <?>.', element, class);
+ this.assertBlock(message, function() {
+ return !!element.className.match(new RegExp(class))
+ });
+ },
+
assertHidden: function(element, message) {
+ element = JsUnitTest.$(element);
message = this.buildMessage(message || 'assertHidden', '? isn\'t hidden.', element);
this.assertBlock(message, function() { return !element.style.display || element.style.display == 'none' });
},
@@ -162,6 +162,13 @@
assertNotInstanceOf(String, {});
}},
+ testHasClass: function() { with(this) {
+ // <div id="test_1" class="a bbbbbbbbbbbb cccccccccc dddd"> </div>
+ assertHasClass('test_1', 'a');
+ // info(document.getElementById('test_1').className);
+ assertHasClass(document.getElementById('test_1'), 'dddd');
+ }},
+
testAssertVisible: function() { with(this) {
assertVisible('testcss1');
assertNotVisible('testcss1_span');

0 comments on commit b233d98

Please sign in to comment.