Added $(...).map() functionality. (Also closes #1250, imo)
[jquery.git] / src / jquery / coreTest.js
index ff8909c..40be7f8 100644 (file)
@@ -604,6 +604,54 @@ test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
        ok( expected == $('#en').text(), "Insert jQuery after" );
 });
 
+test("replaceWith(String|Element|Array<Element>|jQuery)", function() {
+       expect(10);
+       $('#yahoo').replaceWith('<b id="replace">buga</b>');
+       ok( $("#replace")[0], 'Replace element with string' );
+       ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' );
+       
+       reset();
+       $('#yahoo').replaceWith(document.getElementById('first'));
+       ok( $("#first")[0], 'Replace element with element' );
+       ok( !$("#yahoo")[0], 'Verify that original element is gone, after element' );
+
+       reset();
+       $('#yahoo').replaceWith([document.getElementById('first'), document.getElementById('mark')]);
+       ok( $("#first")[0], 'Replace element with array of elements' );
+       ok( $("#mark")[0], 'Replace element with array of elements' );
+       ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
+       
+       reset();
+       $('#yahoo').replaceWith($("#first, #mark"));
+       ok( $("#first")[0], 'Replace element with set of elements' );
+       ok( $("#mark")[0], 'Replace element with set of elements' );
+       ok( !$("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
+});
+
+test("replaceAll(String|Element|Array&lt;Element&gt;|jQuery)", function() {
+       expect(10);
+       $('<b id="replace">buga</b>').replaceAll("#yahoo");
+       ok( $("#replace")[0], 'Replace element with string' );
+       ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' );
+       
+       reset();
+       $(document.getElementById('first')).replaceAll("#yahoo");
+       ok( $("#first")[0], 'Replace element with element' );
+       ok( !$("#yahoo")[0], 'Verify that original element is gone, after element' );
+
+       reset();
+       $([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
+       ok( $("#first")[0], 'Replace element with array of elements' );
+       ok( $("#mark")[0], 'Replace element with array of elements' );
+       ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
+       
+       reset();
+       $("#first, #mark").replaceAll("#yahoo");
+       ok( $("#first")[0], 'Replace element with set of elements' );
+       ok( $("#mark")[0], 'Replace element with set of elements' );
+       ok( !$("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
+});
+
 test("end()", function() {
        expect(3);
        ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
@@ -680,7 +728,7 @@ test("$.extend(Object, Object)", function() {
        isObj( settings, merged, "Check if extended: settings must be extended" );
        isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
 
-       jQuery.extend(deep1, deep2);
+       jQuery.extend(true, deep1, deep2);
        isObj( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" );
        isObj( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
 
@@ -928,3 +976,23 @@ test("slice()", function() {
        isSet( $("#ap a").slice(0,3), q("google", "groups", "anchor1"), "slice(0,3)" );
        isSet( $("#ap a").slice(-1), q("mark"), "slice(-1)" );
 });
+
+test("map()", function() {
+       expect(2);
+
+       isSet(
+               $("#ap").map(function(){
+                       return $(this).find("a").get();
+               }),
+               q("google", "groups", "anchor1", "mark"),
+               "Array Map"
+       );
+
+       isSet(
+               $("#ap > a").map(function(){
+                       return this.parentNode;
+               }),
+               q("ap","ap","ap"),
+               "Single Map"
+       );
+});