From 97ea47492fe13ddb1108045c244d5af6570ace92 Mon Sep 17 00:00:00 2001
From: =?utf8?q?J=C3=B6rn=20Zaefferer?=
Everything inside the red border is inside a div with
- id="foo"
.
This is a normal link: - Yahoo
-This link has class="blog"
:
- Simon Willison's Weblog
Everything inside the red border is inside a div with id="foo"
.
This is a normal link: Yahoo
+This link has class="blog"
: Simon Willison's Weblog
Try them out:
+ +Try them out:
Test Paragraph.
* @result red * + * @test ok( $('#foo').css("display") == 'block', 'Check for css property "display"'); + * * @name css * @type Object * @param String name The name of the property to access. @@ -439,6 +478,12 @@ jQuery.fn = jQuery.prototype = { * @beforeTest Paragraph.
* @resultTest Paragraph.
* + * @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 * @type jQuery * @param Hash prop A set of key/value pairs to set as style properties. @@ -452,6 +497,12 @@ jQuery.fn = jQuery.prototype = { * @beforeTest Paragraph.
* @resultTest Paragraph.
* + * @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 * @type jQuery * @param String key The name of the property to set. @@ -471,6 +522,9 @@ jQuery.fn = jQuery.prototype = { * @beforeTest 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 * @type String * @cat DOM @@ -503,6 +557,11 @@ jQuery.fn = jQuery.prototype = { * @beforeTest Paragraph.
* @resultTest Paragraph.
I would like to say:
* @resultI would like to say: Hello
* + * @test var defaultText = 'Try them out:' + * var result = $('#first').append('buga'); + * ok( result.text() == defaultText + 'buga', 'Check if text appending works' ); + * * @name append * @type jQuery * @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 = { * @beforeI would like to say:
Hello * @resultI would like to say: Hello
* + * @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 * @type jQuery * @param Element elem A DOM element that will be appended. @@ -589,6 +656,10 @@ jQuery.fn = jQuery.prototype = { * @beforeI would like to say:
Hello * @resultI would like to say: Hello
* + * @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 * @type jQuery * @param ArrayI would like to say:
* @resultHelloI would like to say:
* + * @test var defaultText = 'Try them out:' + * var result = $('#first').prepend('buga'); + * ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' ); + * * @name prepend * @type jQuery * @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 * beginning, of all the matched element. * * @example $("p").prepend( $("#foo")[0] ); * @beforeI would like to say:
Hello * @resultHelloI would like to say:
+ * + * @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 * @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 * beginning, of all the matched element. * @@ -640,6 +719,10 @@ jQuery.fn = jQuery.prototype = { * @beforeI would like to say:
Hello * @resultHelloI would like to say:
* + * @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 * @type jQuery * @param ArrayI would like to say:
* @result HelloI would like to say:
* + * @test var expected = 'This is a normal link: bugaYahoo'; + * $('#yahoo').before('buga'); + * ok( expected == $('#en').text(), 'Insert String before' ); + * * @name before * @type jQuery * @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 = { * @beforeI would like to say:
Hello * @result HelloI would like to say:
* + * @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 * @type jQuery * @param Element elem A DOM element that will be appended. @@ -685,6 +776,10 @@ jQuery.fn = jQuery.prototype = { * @beforeI would like to say:
Hello * @result HelloI would like to say:
* + * @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 * @type jQuery * @param ArrayI would like to say:
* @resultI would like to say:
Hello * + * @test var expected = 'This is a normal link: Yahoobuga'; + * $('#yahoo').after('buga'); + * ok( expected == $('#en').text(), 'Insert String after' ); + * * @name after * @type jQuery * @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 HelloI would like to say:
* @resultI would like to say:
Hello * + * @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 * @type jQuery * @param Element elem A DOM element that will be appended. @@ -730,6 +833,10 @@ jQuery.fn = jQuery.prototype = { * @before HelloI would like to say:
* @resultI would like to say:
Hello * + * @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 * @type jQuery * @param ArrayHello, how are you?
* @result $("p").find("span").end() == [...
] * + * @test ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' ); + * * @name end * @type jQuery * @cat DOM/Traversing @@ -770,6 +879,8 @@ jQuery.fn = jQuery.prototype = { * @beforeHello, how are you?
* @result $("p").find("span") == [ Hello ] * + * @test ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' ); + * * @name find * @type jQuery * @param String expr An expression to search with. @@ -792,6 +903,11 @@ jQuery.fn = jQuery.prototype = { * @before Hello, how are you?
* @result HelloHello, how are you?
* + * @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 * @type jQuery * @cat DOM/Manipulation @@ -938,17 +1054,55 @@ jQuery.fn = jQuery.prototype = { }, /** - * A wrapper function for each() to be used by append and prepend. - * Handles cases where you're trying to modify the inner contents of - * a table, when you actually need to work with the tbody. - * - * @member jQuery - * @param {String} expr The expression with which to filter + * Checks the current selection against an expression and returns true, + * if the selection fits the given expression. Does return false, if the + * selection does not fit or the expression is not valid. + * + * @example $("input[@type='checkbox']").parent().is("form") + * @before + * @result true + * @desc Returns true, because the parent of the input is a form element + * + * @example $("input[@type='checkbox']").parent().is("form") + * @before + * @result false + * @desc Returns false, because the parent of the input is a p element + * + * @example $("form").is(null) + * @before + * @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 + * @param String expr The expression with which to filter * @cat DOM/Traversing */ 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, * 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 * @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( "Disabled UI Element", "input:disabled", ["text2"] ); * @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 Groups')", ["groups"] ); * @test t( "Element Preceded By", "p ~ div", ["foo"] ); @@ -2289,6 +2457,9 @@ jQuery.macros = { * @before * @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 * @type String * @cat DOM/Attributes @@ -2301,6 +2472,11 @@ jQuery.macros = { * @before * @result * + * @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 * @type jQuery * @param String val Set the property to the specified value. -- 2.39.5