From: Amey Sakhadeo Date: Thu, 12 Sep 2013 16:18:36 +0000 (-0500) Subject: Add unit tests for jQuery.grep. Close gh-1345. X-Git-Tag: 2.1.0-beta1~15 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=18099d52d831609bf63d1140a0dc63b5bd117f5e;p=jquery.git Add unit tests for jQuery.grep. Close gh-1345. --- diff --git a/test/unit/core.js b/test/unit/core.js index f00907427..5677ddc3d 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -964,6 +964,26 @@ test("jQuery.merge()", function() { ); }); +test("jQuery.grep()", function() { + expect(8); + + var searchCriterion = function( value ) { + return value % 2 === 0; + }; + + deepEqual( jQuery.grep( [], searchCriterion ), [], "Empty array" ); + deepEqual( jQuery.grep( new Array(4), searchCriterion ), [], "Sparse array" ); + + deepEqual( jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion ), [ 2, 4, 6 ], "Satisfying elements present" ); + deepEqual( jQuery.grep( [ 1, 3, 5, 7], searchCriterion ), [], "Satisfying elements absent" ); + + deepEqual( jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion, true ), [ 1, 3, 5 ], "Satisfying elements present and grep inverted" ); + deepEqual( jQuery.grep( [ 1, 3, 5, 7], searchCriterion, true ), [1, 3, 5, 7], "Satisfying elements absent and grep inverted" ); + + deepEqual( jQuery.grep( [ 1, 2, 3, 4, 5, 6 ], searchCriterion, false ), [ 2, 4, 6 ], "Satisfying elements present but grep explicitly uninverted" ); + deepEqual( jQuery.grep( [ 1, 3, 5, 7 ], searchCriterion, false ), [], "Satisfying elements absent and grep explicitly uninverted" ); +}); + test("jQuery.extend(Object, Object)", function() { expect(28);