Skip to content

Commit

Permalink
Added assertNotHasClass; bumped to 0.7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
drnic committed Mar 21, 2009
1 parent f7b50e8 commit f981de0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
5 changes: 5 additions & 0 deletions History.txt
@@ -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]
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -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"
Expand Down
17 changes: 15 additions & 2 deletions src/assertions.js
Expand Up @@ -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)));
});
},

Expand Down
7 changes: 6 additions & 1 deletion test/unit/assertions_test.html
Expand Up @@ -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');
Expand Down

0 comments on commit f981de0

Please sign in to comment.