Improved test suite to reset fixture after each test, added selects to test ':selected'; Added docs for index(obj); Modified is(expr) to return false for an invalid expression, changed docs, too; Added lots of testcases; Changed filename of testfiles: adding leading zeros

This commit is contained in:
Jörn Zaefferer 2006-09-04 04:51:57 +00:00
parent 519b7d33e2
commit 97ea47492f
4 changed files with 305 additions and 68 deletions

View file

@ -4,7 +4,7 @@
<script type="text/javascript" src="js/test.js"></script> <script type="text/javascript" src="js/test.js"></script>
<script> <script>
$(document).ready(function(){ $(document).ready(function(){
runTests([{FILES}]); runTests([{FILES}]);
}); });
</script> </script>
<style>.pass { color: green; } .fail { color: red; } #tests ol { display: none; }</style> <style>.pass { color: green; } .fail { color: red; } #tests ol { display: none; }</style>
@ -24,15 +24,12 @@
</p> </p>
<div id="foo"> <div id="foo">
<p id="sndp">Everything inside the red border is inside a div with <p id="sndp">Everything inside the red border is inside a div with <code>id="foo"</code>.</p>
<code>id="foo"</code>.</p> <p lang="en" id="en">This is a normal link: <a id="yahoo" href="http://www.yahoo.com/" class="blogTest">Yahoo</a></p>
<p lang="en" id="en">This is a normal link: <p id="sap">This link has <code><a href="#2" id="anchor2">class="blog"</a></code>: <a href="http://simon.incutio.com/" class="blog link" id="simon">Simon Willison's Weblog</a></p>
<a id="yahoo" href="http://www.yahoo.com/" class="blogTest">Yahoo</a></p>
<p id="sap">This link has <code><a href="#2" id="anchor2">class="blog"</a></code>:
<a href="http://simon.incutio.com/" class="blog link" id="simon">Simon Willison's Weblog</a></p>
</div> </div>
<p id="first">Try them out: </p> <p id="first">Try them out:</p>
<ul id="firstUL"></ul> <ul id="firstUL"></ul>
<ol id="empty"></ol> <ol id="empty"></ol>
<form id="form"> <form id="form">
@ -45,7 +42,26 @@
<input type="checkbox" name="check" id="check2"/> <input type="checkbox" name="check" id="check2"/>
<input type="hidden" name="hidden" id="hidden1"/> <input type="hidden" name="hidden" id="hidden1"/>
<input type="text" style="display:none;" id="hidden2"/> <input type="text" style="display:none;" id="hidden2"/>
<select name="select1" id="select1">
<option id="option1a" value="">Nothing</option>
<option id="option1b" value="1">1</option>
<option id="option1c" value="2">2</option>
<option id="option1d" value="3">3</option>
</select>
<select name="select1" id="select2">
<option id="option2a" value="">Nothing</option>
<option id="option2b" value="1">1</option>
<option id="option2c" value="2">2</option>
<option id="option2d" selected value="3">3</option>
</select>
<select name="select3" id="select3" multiple="multiple">
<option id="option3a" value="">Nothing</option>
<option id="option3b" selected="selected" value="1">1</option>
<option id="option3c" selected value="2">2</option>
<option id="option3d" value="3">3</option>
</select>
</form> </form>
</div> </div>
</dl> </dl>

View file

@ -1,53 +1,97 @@
var queue = [];
var blocking = false;
function reset() {
synchronize(function() {
blocking = true;
$.get('index.html', function(content) {
var div = $(document.createElement('div')).html(content)
// search for main div
.find('[@id=main]').html();
$('#main').html(div);
blocking = false;
process();
});
});
}
function synchronize(callback) {
queue[queue.length] = callback;
if(!blocking) {
process();
}
}
function process() {
while(queue.length && !blocking) {
var call = queue[0];
queue = queue.slice(1);
call();
}
}
function runTests(files) { function runTests(files) {
runTest( files, 0 ); var startTime = new Date();
for( var i=0; i < files.length; i++) {
runTest( files, i );
reset();
}
synchronize(function() {
var runTime = new Date() - startTime;
$('body').append('<br/>Tests completed in ' + runTime + ' milliseconds.');
});
} }
function runTest( files, num ) { function runTest( files, num ) {
$.get(files[num],function(js){ synchronize(function() {
js = js.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&"); blocking = true;
$.get(files[num],function(js){
try { js = js.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
eval(js);
} catch(e) { try {
Test.push( [ false, "Died on test #" + Test.length + ": " + e ] ); eval(js);
} } catch(e) {
Test.push( [ false, "Died on test #" + (Test.length+1) + ": " + e ] );
var good = 0, bad = 0; }
var ol = document.createElement("ol");
var good = 0, bad = 0;
var li = "", state = "pass"; var ol = document.createElement("ol");
for ( var i = 0; i < Test.length; i++ ) {
var li = "", state = "pass";
for ( var i = 0; i < Test.length; i++ ) {
var li = document.createElement("li");
li.className = Test[i][0] ? "pass" : "fail";
li.innerHTML = Test[i][1];
ol.appendChild( li );
if ( !Test[i][0] ) {
state = "fail";
bad++;
} else good++;
}
var li = document.createElement("li"); var li = document.createElement("li");
li.className = Test[i][0] ? "pass" : "fail"; li.className = state;
li.innerHTML = Test[i][1];
ol.appendChild( li ); var b = document.createElement("b");
b.innerHTML = files[num] + " <b style='color:black;'>(<b class='fail'>" + bad + "</b>, <b class='pass'>" + good + "</b>, " + Test.length + ")</b>";
if ( !Test[i][0] ) { b.onclick = function(){
state = "fail"; var n = this.nextSibling;
bad++; if ( jQuery.css( n, "display" ) == "none" )
} else good++; n.style.display = "block";
} else
n.style.display = "none";
var li = document.createElement("li"); };
li.className = state; li.appendChild( b );
var b = document.createElement("b"); li.appendChild( ol );
b.innerHTML = files[num] + " <b style='color:black;'>(<b class='fail'>" + bad + "</b>, <b class='pass'>" + good + "</b>, " + Test.length + ")</b>";
b.onclick = function(){ document.getElementById("tests").appendChild( li );
var n = this.nextSibling;
if ( jQuery.css( n, "display" ) == "none" ) Test = [];
n.style.display = "block"; blocking = false;
else process();
n.style.display = "none"; });
};
li.appendChild( b );
li.appendChild( ol );
document.getElementById("tests").appendChild( li );
Test = [];
if ( ++num < files.length ) runTest( files, num );
}); });
} }

View file

@ -13,11 +13,12 @@ var count = 1;
for ( var i = 0; i < jq.length; i++ ) { for ( var i = 0; i < jq.length; i++ ) {
if ( jq[i].tests.length > 0 ) { if ( jq[i].tests.length > 0 ) {
var name = count + "-" + jq[i].name; var name = count + "-" + jq[i].name;
if(count < 100) {
var myFile = testFile name = "0" + name;
.replace( /{TITLE}/g, jq[i].name ) }
.replace( /{NUM}/g, jq[i].tests.length ) if(count < 10) {
.replace( /{TESTS}/g, jq[i].tests.join("\n") ); name = "0" + name;
}
var fileName = "tests/" + name + ".js"; var fileName = "tests/" + name + ".js";

192
src/jquery/jquery.js vendored
View file

@ -325,6 +325,38 @@ jQuery.fn = jQuery.prototype = {
return jQuery.each( this, fn, args ); return jQuery.each( this, fn, args );
}, },
/**
* Searches every matched element for the object and returns
* the index of the element, if found, starting with zero.
* Returns -1 if the object wasn't found.
*
* @example $("*").index(document.getElementById('foobar'))
* @before <div id="foobar"></div><b></b><span id="foo"></span>
* @result 0
*
* @example $("*").index(document.getElementById('foo'))
* @before <div id="foobar"></div><b></b><span id="foo"></span>
* @result 2
*
* @example $("*").index(document.getElementById('bar'))
* @before <div id="foobar"></div><b></b><span id="foo"></span>
* @result -1
*
* @test ok( $([window, document]).index(window) == 0, "Check for index of elements" );
* ok( $([window, document]).index(document) == 1, "Check for index of elements" );
* var inputElements = $('#radio1,#radio2,#check1,#check2');
* ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
* ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
* ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
* ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
* ok( inputElements.index(window) == -1, "Check for not found index" );
* ok( inputElements.index(document) == -1, "Check for not found index" );
*
* @name index
* @type Number
* @param Object obj Object to search for
* @cat Core
*/
index: function( obj ) { index: function( obj ) {
var pos = -1; var pos = -1;
this.each(function(i){ this.each(function(i){
@ -342,6 +374,11 @@ jQuery.fn = jQuery.prototype = {
* @before <img src="test.jpg"/> * @before <img src="test.jpg"/>
* @result test.jpg * @result test.jpg
* *
* @test ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
* @test ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
* @test ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
* @test ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
*
* @name attr * @name attr
* @type Object * @type Object
* @param String name The name of the property to access. * @param String name The name of the property to access.
@ -424,6 +461,8 @@ jQuery.fn = jQuery.prototype = {
* @before <p style="color:red;">Test Paragraph.</p> * @before <p style="color:red;">Test Paragraph.</p>
* @result red * @result red
* *
* @test ok( $('#foo').css("display") == 'block', 'Check for css property "display"');
*
* @name css * @name css
* @type Object * @type Object
* @param String name The name of the property to access. * @param String name The name of the property to access.
@ -439,6 +478,12 @@ jQuery.fn = jQuery.prototype = {
* @before <p>Test Paragraph.</p> * @before <p>Test Paragraph.</p>
* @result <p style="color:red; background:blue;">Test Paragraph.</p> * @result <p style="color:red; background:blue;">Test Paragraph.</p>
* *
* @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
* $('#foo').css({display: 'none'});
* ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
* $('#foo').css({display: 'block'});
* ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
*
* @name css * @name css
* @type jQuery * @type jQuery
* @param Hash prop A set of key/value pairs to set as style properties. * @param Hash prop A set of key/value pairs to set as style properties.
@ -452,6 +497,12 @@ jQuery.fn = jQuery.prototype = {
* @before <p>Test Paragraph.</p> * @before <p>Test Paragraph.</p>
* @result <p style="color:red;">Test Paragraph.</p> * @result <p style="color:red;">Test Paragraph.</p>
* *
* @test ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
* $('#foo').css('display', 'none');
* ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
* $('#foo').css('display', 'block');
* ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
*
* @name css * @name css
* @type jQuery * @type jQuery
* @param String key The name of the property to set. * @param String key The name of the property to set.
@ -471,6 +522,9 @@ jQuery.fn = jQuery.prototype = {
* @before <p>Test Paragraph.</p> * @before <p>Test Paragraph.</p>
* @result Test Paragraph. * @result Test Paragraph.
* *
* @test var expected = "This link has class=\"blog\": Simon Willison's Weblog";
* ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
*
* @name text * @name text
* @type String * @type String
* @cat DOM * @cat DOM
@ -503,6 +557,11 @@ jQuery.fn = jQuery.prototype = {
* @before <p>Test Paragraph.</p> * @before <p>Test Paragraph.</p>
* @result <div class='wrap'><p>Test Paragraph.</p></div> * @result <div class='wrap'><p>Test Paragraph.</p></div>
* *
* @test var defaultText = 'Try them out:'
* var result = $('#first').wrap('<div class="red">xx<span></span>yy</div>').text()
* ok( 'xx' + defaultText + 'yy' == result, 'Check for wrapping' );
* ok( $('#first').parent().parent().is('.red'), 'Check if wrapper div has class "red"' );
*
* @name wrap * @name wrap
* @type jQuery * @type jQuery
* @param String html A string of HTML, that will be created on the fly and wrapped around the target. * @param String html A string of HTML, that will be created on the fly and wrapped around the target.
@ -559,6 +618,10 @@ jQuery.fn = jQuery.prototype = {
* @before <p>I would like to say: </p> * @before <p>I would like to say: </p>
* @result <p>I would like to say: <b>Hello</b></p> * @result <p>I would like to say: <b>Hello</b></p>
* *
* @test var defaultText = 'Try them out:'
* var result = $('#first').append('<b>buga</b>');
* ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
*
* @name append * @name append
* @type jQuery * @type jQuery
* @param String html A string of HTML, that will be created on the fly and appended to the target. * @param String html A string of HTML, that will be created on the fly and appended to the target.
@ -574,6 +637,10 @@ jQuery.fn = jQuery.prototype = {
* @before <p>I would like to say: </p><b id="foo">Hello</b> * @before <p>I would like to say: </p><b id="foo">Hello</b>
* @result <p>I would like to say: <b id="foo">Hello</b></p> * @result <p>I would like to say: <b id="foo">Hello</b></p>
* *
* @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
* $('#sap').append(document.getElementById('first'));
* ok( expected == $('#sap').text(), "Check for appending of element" );
*
* @name append * @name append
* @type jQuery * @type jQuery
* @param Element elem A DOM element that will be appended. * @param Element elem A DOM element that will be appended.
@ -589,6 +656,10 @@ jQuery.fn = jQuery.prototype = {
* @before <p>I would like to say: </p><b>Hello</b> * @before <p>I would like to say: </p><b>Hello</b>
* @result <p>I would like to say: <b>Hello</b></p> * @result <p>I would like to say: <b>Hello</b></p>
* *
* @test var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
* $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
* ok( expected == $('#sap').text(), "Check for appending of array of elements" );
*
* @name append * @name append
* @type jQuery * @type jQuery
* @param Array<Element> elems An array of elements, all of which will be appended. * @param Array<Element> elems An array of elements, all of which will be appended.
@ -610,6 +681,10 @@ jQuery.fn = jQuery.prototype = {
* @before <p>I would like to say: </p> * @before <p>I would like to say: </p>
* @result <p><b>Hello</b>I would like to say: </p> * @result <p><b>Hello</b>I would like to say: </p>
* *
* @test var defaultText = 'Try them out:'
* var result = $('#first').prepend('<b>buga</b>');
* ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
*
* @name prepend * @name prepend
* @type jQuery * @type jQuery
* @param String html A string of HTML, that will be created on the fly and appended to the target. * @param String html A string of HTML, that will be created on the fly and appended to the target.
@ -617,13 +692,17 @@ jQuery.fn = jQuery.prototype = {
*/ */
/** /**
* Append an element to the inside of all matched elements. * Prepend an element to the inside of all matched elements.
* This operation is the best way to insert an element inside, at the * This operation is the best way to insert an element inside, at the
* beginning, of all the matched element. * beginning, of all the matched element.
* *
* @example $("p").prepend( $("#foo")[0] ); * @example $("p").prepend( $("#foo")[0] );
* @before <p>I would like to say: </p><b id="foo">Hello</b> * @before <p>I would like to say: </p><b id="foo">Hello</b>
* @result <p><b id="foo">Hello</b>I would like to say: </p> * @result <p><b id="foo">Hello</b>I would like to say: </p>
*
* @test var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
* $('#sap').prepend(document.getElementById('first'));
* ok( expected == $('#sap').text(), "Check for prepending of element" );
* *
* @name prepend * @name prepend
* @type jQuery * @type jQuery
@ -632,7 +711,7 @@ jQuery.fn = jQuery.prototype = {
*/ */
/** /**
* Append any number of elements to the inside of all matched elements. * Prepend any number of elements to the inside of all matched elements.
* This operation is the best way to insert a set of elements inside, at the * This operation is the best way to insert a set of elements inside, at the
* beginning, of all the matched element. * beginning, of all the matched element.
* *
@ -640,6 +719,10 @@ jQuery.fn = jQuery.prototype = {
* @before <p>I would like to say: </p><b>Hello</b> * @before <p>I would like to say: </p><b>Hello</b>
* @result <p><b>Hello</b>I would like to say: </p> * @result <p><b>Hello</b>I would like to say: </p>
* *
* @test var expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
* $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
* ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
*
* @name prepend * @name prepend
* @type jQuery * @type jQuery
* @param Array<Element> elems An array of elements, all of which will be appended. * @param Array<Element> elems An array of elements, all of which will be appended.
@ -659,6 +742,10 @@ jQuery.fn = jQuery.prototype = {
* @before <p>I would like to say: </p> * @before <p>I would like to say: </p>
* @result <b>Hello</b><p>I would like to say: </p> * @result <b>Hello</b><p>I would like to say: </p>
* *
* @test var expected = 'This is a normal link: bugaYahoo';
* $('#yahoo').before('<b>buga</b>');
* ok( expected == $('#en').text(), 'Insert String before' );
*
* @name before * @name before
* @type jQuery * @type jQuery
* @param String html A string of HTML, that will be created on the fly and appended to the target. * @param String html A string of HTML, that will be created on the fly and appended to the target.
@ -672,6 +759,10 @@ jQuery.fn = jQuery.prototype = {
* @before <p>I would like to say: </p><b id="foo">Hello</b> * @before <p>I would like to say: </p><b id="foo">Hello</b>
* @result <b id="foo">Hello</b><p>I would like to say: </p> * @result <b id="foo">Hello</b><p>I would like to say: </p>
* *
* @test var expected = "This is a normal link: Try them out:Yahoo";
* $('#yahoo').before(document.getElementById('first'));
* ok( expected == $('#en').text(), "Insert element before" );
*
* @name before * @name before
* @type jQuery * @type jQuery
* @param Element elem A DOM element that will be appended. * @param Element elem A DOM element that will be appended.
@ -685,6 +776,10 @@ jQuery.fn = jQuery.prototype = {
* @before <p>I would like to say: </p><b>Hello</b> * @before <p>I would like to say: </p><b>Hello</b>
* @result <b>Hello</b><p>I would like to say: </p> * @result <b>Hello</b><p>I would like to say: </p>
* *
* @test var expected = "This is a normal link: Try them out:diveintomarkYahoo";
* $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
* ok( expected == $('#en').text(), "Insert array of elements before" );
*
* @name before * @name before
* @type jQuery * @type jQuery
* @param Array<Element> elems An array of elements, all of which will be appended. * @param Array<Element> elems An array of elements, all of which will be appended.
@ -704,6 +799,10 @@ jQuery.fn = jQuery.prototype = {
* @before <p>I would like to say: </p> * @before <p>I would like to say: </p>
* @result <p>I would like to say: </p><b>Hello</b> * @result <p>I would like to say: </p><b>Hello</b>
* *
* @test var expected = 'This is a normal link: Yahoobuga';
* $('#yahoo').after('<b>buga</b>');
* ok( expected == $('#en').text(), 'Insert String after' );
*
* @name after * @name after
* @type jQuery * @type jQuery
* @param String html A string of HTML, that will be created on the fly and appended to the target. * @param String html A string of HTML, that will be created on the fly and appended to the target.
@ -717,6 +816,10 @@ jQuery.fn = jQuery.prototype = {
* @before <b id="foo">Hello</b><p>I would like to say: </p> * @before <b id="foo">Hello</b><p>I would like to say: </p>
* @result <p>I would like to say: </p><b id="foo">Hello</b> * @result <p>I would like to say: </p><b id="foo">Hello</b>
* *
* @test var expected = "This is a normal link: YahooTry them out:";
* $('#yahoo').after(document.getElementById('first'));
* ok( expected == $('#en').text(), "Insert element after" );
*
* @name after * @name after
* @type jQuery * @type jQuery
* @param Element elem A DOM element that will be appended. * @param Element elem A DOM element that will be appended.
@ -730,6 +833,10 @@ jQuery.fn = jQuery.prototype = {
* @before <b>Hello</b><p>I would like to say: </p> * @before <b>Hello</b><p>I would like to say: </p>
* @result <p>I would like to say: </p><b>Hello</b> * @result <p>I would like to say: </p><b>Hello</b>
* *
* @test var expected = "This is a normal link: YahooTry them out:diveintomark";
* $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
* ok( expected == $('#en').text(), "Insert array of elements after" );
*
* @name after * @name after
* @type jQuery * @type jQuery
* @param Array<Element> elems An array of elements, all of which will be appended. * @param Array<Element> elems An array of elements, all of which will be appended.
@ -750,6 +857,8 @@ jQuery.fn = jQuery.prototype = {
* @before <p><span>Hello</span>, how are you?</p> * @before <p><span>Hello</span>, how are you?</p>
* @result $("p").find("span").end() == [ <p>...</p> ] * @result $("p").find("span").end() == [ <p>...</p> ]
* *
* @test ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
*
* @name end * @name end
* @type jQuery * @type jQuery
* @cat DOM/Traversing * @cat DOM/Traversing
@ -770,6 +879,8 @@ jQuery.fn = jQuery.prototype = {
* @before <p><span>Hello</span>, how are you?</p> * @before <p><span>Hello</span>, how are you?</p>
* @result $("p").find("span") == [ <span>Hello</span> ] * @result $("p").find("span") == [ <span>Hello</span> ]
* *
* @test ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
*
* @name find * @name find
* @type jQuery * @type jQuery
* @param String expr An expression to search with. * @param String expr An expression to search with.
@ -792,6 +903,11 @@ jQuery.fn = jQuery.prototype = {
* @before <b>Hello</b><p>, how are you?</p> * @before <b>Hello</b><p>, how are you?</p>
* @result <b>Hello</b><p><b>Hello</b>, how are you?</p> * @result <b>Hello</b><p><b>Hello</b>, how are you?</p>
* *
* @test ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
* var clone = $('#yahoo').clone();
* ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
* ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
*
* @name clone * @name clone
* @type jQuery * @type jQuery
* @cat DOM/Manipulation * @cat DOM/Manipulation
@ -938,17 +1054,55 @@ jQuery.fn = jQuery.prototype = {
}, },
/** /**
* A wrapper function for each() to be used by append and prepend. * Checks the current selection against an expression and returns true,
* Handles cases where you're trying to modify the inner contents of * if the selection fits the given expression. Does return false, if the
* a table, when you actually need to work with the tbody. * selection does not fit or the expression is not valid.
* *
* @member jQuery * @example $("input[@type='checkbox']").parent().is("form")
* @param {String} expr The expression with which to filter * @before <form><input type="checkbox" /></form>
* @result true
* @desc Returns true, because the parent of the input is a form element
*
* @example $("input[@type='checkbox']").parent().is("form")
* @before <form><p><input type="checkbox" /></p></form>
* @result false
* @desc Returns false, because the parent of the input is a p element
*
* @example $("form").is(null)
* @before <form></form>
* @result false
* @desc An invalid expression always returns false.
*
* @test ok( $('#form').is('form'), 'Check for element: A form must be a form' );
* @test ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
* @test ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
* @test ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
* @test ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
* @test ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
* @test ok( $('#en').is('[@lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
* @test ok( !$('#en').is('[@lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
* @test ok( $('#text1').is('[@type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
* @test ok( !$('#text1').is('[@type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
* @test ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
* @test ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
* @test ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
* @test ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
* @test ok( $('#foo').is('[p]'), 'Check for child: Expected a child "p" element' );
* @test ok( !$('#foo').is('[ul]'), 'Check for child: Did not expect "ul" element' );
* @test ok( $('#foo').is('[p][a][code]'), 'Check for childs: Expected "p", "a" and "code" child elements' );
* @test ok( !$('#foo').is('[p][a][code][ol]'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
* @test ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
* @test ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
* @test ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
* @test ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
*
* @name is
* @type Boolean * @type Boolean
* @param String expr The expression with which to filter
* @cat DOM/Traversing * @cat DOM/Traversing
*/ */
is: function(expr) { is: function(expr) {
return expr ? jQuery.filter(expr,this).r.length > 0 : this.length > 0; return expr ? jQuery.filter(expr,this).r.length > 0 : false;
}, },
/** /**
@ -1029,6 +1183,19 @@ jQuery.fn = jQuery.prototype = {
/** /**
* Extend one object with another, returning the original, * Extend one object with another, returning the original,
* modified, object. This is a great utility for simple inheritance. * modified, object. This is a great utility for simple inheritance.
*
* @example var settings = { validate: false, limit: 5, name: "foo" };
* var options = { validate: true, name: "bar" };
* jQuery.extend(settings, options);
* @result settings == { validate: true, limit: 5, name: "bar" }
*
* @test var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" };
* var options = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
* var optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" };
* var merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" };
* jQuery.extend(settings, options);
* isSet( settings, merged, "Check if extended: settings must be extended" );
* isSet ( options, optionsCopy, "Check if not modified: options must not be modified" );
* *
* @name $.extend * @name $.extend
* @param Object obj The object to extend * @param Object obj The object to extend
@ -1380,6 +1547,7 @@ jQuery.extend({
* @test t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2"] ); * @test t( "Enabled UI Element", "input:enabled", ["text1","radio1","radio2","check1","check2","hidden1","hidden2"] );
* @test t( "Disabled UI Element", "input:disabled", ["text2"] ); * @test t( "Disabled UI Element", "input:disabled", ["text2"] );
* @test t( "Checked UI Element", "input:checked", ["radio2","check1"] ); * @test t( "Checked UI Element", "input:checked", ["radio2","check1"] );
* @test t( "Selected Option Element", "option:selected", ["option1a","option2d","option3b","option3c"] );
* @test t( "Text Contains", "a:contains('Google')", ["google","groups"] ); * @test t( "Text Contains", "a:contains('Google')", ["google","groups"] );
* @test t( "Text Contains", "a:contains('Google Groups')", ["groups"] ); * @test t( "Text Contains", "a:contains('Google Groups')", ["groups"] );
* @test t( "Element Preceded By", "p ~ div", ["foo"] ); * @test t( "Element Preceded By", "p ~ div", ["foo"] );
@ -2289,6 +2457,9 @@ jQuery.macros = {
* @before <input type="text" value="some text"/> * @before <input type="text" value="some text"/>
* @result "some text" * @result "some text"
* *
* @test ok( $("#text1").val() == "Test", "Check for value of input element" );
* @test ok( !$("#text1").val() == "", "Check for value of input element" );
*
* @name val * @name val
* @type String * @type String
* @cat DOM/Attributes * @cat DOM/Attributes
@ -2301,6 +2472,11 @@ jQuery.macros = {
* @before <input type="text" value="some text"/> * @before <input type="text" value="some text"/>
* @result <input type="text" value="test"/> * @result <input type="text" value="test"/>
* *
* @test document.getElementById('text1').value = "bla";
* ok( $("#text1").val() == "bla", "Check for modified value of input element" );
* $("#text1").val('test');
* ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
*
* @name val * @name val
* @type jQuery * @type jQuery
* @param String val Set the property to the specified value. * @param String val Set the property to the specified value.