]> source.dussan.org Git - jquery-ui.git/commitdiff
Build: Add qunit-assert-classes plug-in for classes tests
authorAlexander Schmitz <arschmitz@gmail.com>
Tue, 3 Feb 2015 00:21:44 +0000 (19:21 -0500)
committerAlexander Schmitz <arschmitz@gmail.com>
Wed, 11 Mar 2015 18:55:44 +0000 (14:55 -0400)
Gruntfile.js
bower.json
external/qunit-assert-classes/LICENSE.txt [new file with mode: 0644]
external/qunit-assert-classes/qunit-assert-classes.js [new file with mode: 0644]

index 3e66e2e37d39d13a4573687eafd8331e5aaf5536..d91dedb9bc4d918350df8dd9c7889dfda771fb8f 100644 (file)
@@ -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",
 
index 38a9f77ee54906ea7975713bc32300df482ed507..9b6b71b6f36e546cde6c439a6809d32777a84355 100644 (file)
@@ -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 (file)
index 0000000..938db03
--- /dev/null
@@ -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 (file)
index 0000000..f61046b
--- /dev/null
@@ -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