Skip to content

Commit

Permalink
Test _.restParam
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed Apr 8, 2015
1 parent d9a6f91 commit 4afa539
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,4 +588,32 @@

});

test('restParam', 10, function() {
_.restParam(function(a, args) {
strictEqual(a, 1);
deepEqual(args, [2, 3], 'collects rest arguments into an array');
})(1, 2, 3);

_.restParam(function(a, args) {
strictEqual(a, undefined);
deepEqual(args, [], 'passes empty array if there are not enough arguments');
})();

_.restParam(function(a, b, c, args) {
strictEqual(arguments.length, 4);
deepEqual(args, [4, 5], 'works on functions with many named parameters');
})(1, 2, 3, 4, 5);

var obj = {};
_.restParam(function() {
strictEqual(this, obj, 'invokes function with this context');
}).call(obj);

_.restParam(function(array, iteratee, context) {
deepEqual(array, [1, 2, 3, 4], 'startIndex can be used manually specify index of rest parameter');
strictEqual(iteratee, undefined);
strictEqual(context, undefined);
}, 0)(1, 2, 3, 4);
});

}());

0 comments on commit 4afa539

Please sign in to comment.