mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Build: Add qunit-assert-classes plug-in for classes tests
This commit is contained in:
parent
8ea36f5e0c
commit
4959c81d80
@ -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",
|
||||
|
22
external/qunit-assert-classes/LICENSE.txt
vendored
Normal file
22
external/qunit-assert-classes/LICENSE.txt
vendored
Normal file
@ -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.
|
||||
|
47
external/qunit-assert-classes/qunit-assert-classes.js
vendored
Normal file
47
external/qunit-assert-classes/qunit-assert-classes.js
vendored
Normal file
@ -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 );
|
Loading…
Reference in New Issue
Block a user