Skip to content
Permalink
Browse files

Build: Add qunit-assert-classes plug-in for classes tests

  • Loading branch information
arschmitz committed Feb 3, 2015
1 parent 8ea36f5 commit 4959c81d80943d097ab29f829488f0551186c1fd
Showing with 73 additions and 0 deletions.
  1. +3 −0 Gruntfile.js
  2. +1 −0 bower.json
  3. +22 −0 external/qunit-assert-classes/LICENSE.txt
  4. +47 −0 external/qunit-assert-classes/qunit-assert-classes.js
@@ -229,6 +229,9 @@ grunt.initConfig({
"qunit/qunit.css": "qunit/qunit/qunit.css",
"qunit/LICENSE.txt": "qunit/LICENSE.txt",

"qunit-assert-classes/qunit-assert-classes.js": "qunit-assert-classes/qunit-assert-classes.js",
"qunit-assert-classes/LICENSE.txt": "qunit-assert-classes/LICENSE",

"jquery-mousewheel/jquery.mousewheel.js": "jquery-mousewheel/jquery.mousewheel.js",
"jquery-mousewheel/LICENSE.txt": "jquery-mousewheel/LICENSE.txt",

@@ -15,6 +15,7 @@
"jquery-simulate": "1.0.0",
"jshint": "2.4.4",
"qunit": "1.17.1",
"qunit-assert-classes": "0.1.5",

"jquery-1.7.0": "jquery#1.7.0",
"jquery-1.7.1": "jquery#1.7.1",
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 Alexander Schmitz

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

@@ -0,0 +1,47 @@
( function( QUnit ) {
function inArray( haystack, needle ) {
for ( var i = 0; i < haystack.length; i++ ) {
if ( haystack[ i ] === needle ) {
return true;
}
}
return false;
}
function check( element, classes, stateVal, message ) {
var i, result, classAttribute, elementClassArray,
classArray = classes.split( " " ),
missing = [],
found = [];

if ( element.jquery && element.length !== 1 ) {
throw( "Class checks can only be performed on a single element on a collection" );
}
element = element.jquery ? element[ 0 ] : element;
classAttribute = element.getAttribute( "class" );
message = message || "Element must " + ( stateVal? "" : "not " ) + "have classes";
if ( classAttribute ) {
elementClassArray = classAttribute.split( " " );
for( i = 0; i < classArray.length; i++ ) {
if ( !inArray( elementClassArray, classArray[ i ] ) ) {
missing.push( classArray[ i ] );
} else {
found.push( classArray[ i ] );
}
}
} else {
missing = classArray;
}

result = stateVal ? !missing.length : !found.length;
QUnit.push( result, classes, result ? classes : found.join( " " ), message );
}

QUnit.extend( QUnit.assert, {
hasClasses: function( element, classes, message ) {
check( element, classes, true, message );
},
lacksClasses: function( element, classes, message ) {
check( element, classes, false, message );
}
});
})( QUnit );

0 comments on commit 4959c81

Please sign in to comment.
You can’t perform that action at this time.