aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Schmitz <arschmitz@gmail.com>2015-02-02 19:21:44 -0500
committerAlexander Schmitz <arschmitz@gmail.com>2015-03-11 14:55:44 -0400
commit4959c81d80943d097ab29f829488f0551186c1fd (patch)
tree0356eac4dfe99c37cee3ca721c1835833e5c4060
parent8ea36f5e0cc389752fdecdd17f0a82a2d560d4bb (diff)
downloadjquery-ui-4959c81d80943d097ab29f829488f0551186c1fd.tar.gz
jquery-ui-4959c81d80943d097ab29f829488f0551186c1fd.zip
Build: Add qunit-assert-classes plug-in for classes tests
-rw-r--r--Gruntfile.js3
-rw-r--r--bower.json1
-rw-r--r--external/qunit-assert-classes/LICENSE.txt22
-rw-r--r--external/qunit-assert-classes/qunit-assert-classes.js47
4 files changed, 73 insertions, 0 deletions
diff --git a/Gruntfile.js b/Gruntfile.js
index 3e66e2e37..d91dedb9b 100644
--- a/Gruntfile.js
+++ b/Gruntfile.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",
diff --git a/bower.json b/bower.json
index 38a9f77ee..9b6b71b6f 100644
--- a/bower.json
+++ b/bower.json
@@ -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",
diff --git a/external/qunit-assert-classes/LICENSE.txt b/external/qunit-assert-classes/LICENSE.txt
new file mode 100644
index 000000000..938db0368
--- /dev/null
+++ b/external/qunit-assert-classes/LICENSE.txt
@@ -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.
+
diff --git a/external/qunit-assert-classes/qunit-assert-classes.js b/external/qunit-assert-classes/qunit-assert-classes.js
new file mode 100644
index 000000000..f61046bc8
--- /dev/null
+++ b/external/qunit-assert-classes/qunit-assert-classes.js
@@ -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 ); \ No newline at end of file