Permalink
Browse files

Added assertNotHasClass; bumped to 0.7.3

  • Loading branch information...
1 parent f7b50e8 commit f981de0def58d1585684777fcf6415c3d594d868 @drnic committed Mar 21, 2009
Showing with 27 additions and 4 deletions.
  1. +5 −0 History.txt
  2. +1 −1 Rakefile
  3. +15 −2 src/assertions.js
  4. +6 −1 test/unit/assertions_test.html
View
@@ -1,3 +1,8 @@
+== 0.7.3 2009-03-21
+
+* New assertions: assertNotHasClass(element, class)
+* Fixed algorithm for assertHasClass
+
== 0.7.2 2008-10-08
* AJAX callback from IE6 working [choan]
View
@@ -12,7 +12,7 @@ require 'rake/packagetask'
$:.unshift File.dirname(__FILE__) + "/lib"
-APP_VERSION = '0.7.2'
+APP_VERSION = '0.7.3'
APP_NAME = 'jsunittest'
RUBYFORGE_PROJECT = 'drnicjavascript'
APP_FILE_NAME= "#{APP_NAME}.js"
View
@@ -146,8 +146,21 @@ JsUnitTest.Unit.Assertions = {
assertHasClass: function(element, klass, message) {
element = JsUnitTest.$(element);
message = this.buildMessage(message || 'assertHasClass', '? doesn\'t have class <?>.', element, klass);
- this.assertBlock(message, function() {
- return !!element.className.match(new RegExp(klass))
+ this.assertBlock(message, function() {
+ var elementClassName = element.className;
+ return (elementClassName.length > 0 && (elementClassName == klass ||
+ new RegExp("(^|\\s)" + klass + "(\\s|$)").test(elementClassName)));
+ // return !!element.className.match(new RegExp(klass))
+ });
+ },
+
+ assertNotHasClass: function(element, klass, message) {
+ element = JsUnitTest.$(element);
+ message = this.buildMessage(message || 'assertNotHasClass', '? does have class <?>.', element, klass);
+ this.assertBlock(message, function() {
+ var elementClassName = element.className;
+ return !(elementClassName.length > 0 && (elementClassName == klass ||
+ new RegExp("(^|\\s)" + klass + "(\\s|$)").test(elementClassName)));
});
},
@@ -165,10 +165,15 @@ <h1>JavaScript unit test file</h1>
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');
}},
+ testNotHasClass: function() { with(this) {
+ // <div id="test_1" class="a bbbbbbbbbbbb cccccccccc dddd"> </div>
+ assertNotHasClass('test_1', 'abc');
+ assertNotHasClass(document.getElementById('test_1'), 'ddd');
+ }},
+
testAssertVisible: function() { with(this) {
assertVisible('testcss1');
assertNotVisible('testcss1_span');

0 comments on commit f981de0

Please sign in to comment.