mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
* test: fix throttle.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix pickBy.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix isBuffer.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: partially fix attempt.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: partially fix dropRightWhile.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix defer.spec.js and rest.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix invoke.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix isArray.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: partially fix iteration-methods.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix xor-methods.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix property.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix ary.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix omit-methods.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix debounce-and-throttle.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix unzip-and-zip.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix toPairs-methods.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix exit-early.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: temporarily comment out takeWhile and dropWhile tests Signed-off-by: tison <wander4096@gmail.com> * test: partially fix union*.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix startsWith-and-endsWith.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix isNil.spec.js Signed-off-by: tison <wander4096@gmail.com> * test: fix some of syntax errors Signed-off-by: tison <wander4096@gmail.com> --------- Signed-off-by: tison <wander4096@gmail.com>
49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
import lodashStable from 'lodash';
|
|
import { slice, _ } from './utils';
|
|
|
|
describe('rest', () => {
|
|
function fn(a, b, c) {
|
|
return slice.call(arguments);
|
|
}
|
|
|
|
it('should apply a rest parameter to `func`', () => {
|
|
const rest = _.rest(fn);
|
|
expect(rest(1, 2, 3, 4)).toEqual([1, 2, [3, 4]]);
|
|
});
|
|
|
|
it('should work with `start`', () => {
|
|
const rest = _.rest(fn, 1);
|
|
expect(rest(1, 2, 3, 4)).toEqual([1, [2, 3, 4]]);
|
|
});
|
|
|
|
it('should treat `start` as `0` for `NaN` or negative values', () => {
|
|
const values = [-1, NaN, 'a'];
|
|
const expected = lodashStable.map(values, lodashStable.constant([[1, 2, 3, 4]]));
|
|
|
|
const actual = lodashStable.map(values, (value) => {
|
|
const rest = _.rest(fn, value);
|
|
return rest(1, 2, 3, 4);
|
|
});
|
|
|
|
expect(actual).toEqual(expected);
|
|
});
|
|
|
|
it('should coerce `start` to an integer', () => {
|
|
const rest = _.rest(fn, 1.6);
|
|
expect(rest(1, 2, 3)).toEqual([1, [2, 3]]);
|
|
});
|
|
|
|
it('should use an empty array when `start` is not reached', () => {
|
|
const rest = _.rest(fn);
|
|
expect(rest(1)).toEqual([1, undefined, []]);
|
|
});
|
|
|
|
it('should work on functions with more than three parameters', () => {
|
|
const rest = _.rest(function (a, b, c, d) {
|
|
return slice.call(arguments);
|
|
});
|
|
|
|
expect(rest(1, 2, 3, 4, 5)).toEqual([1, 2, 3, [4, 5]]);
|
|
});
|
|
});
|