Files
lodash/test/nthArg.spec.js
tison bd518dd906 test: partially fix broken tests (#5733)
* 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>
2023-09-21 07:40:27 -07:00

65 lines
1.9 KiB
JavaScript

import lodashStable from 'lodash';
import { args, falsey, stubA, stubB, noop } from './utils';
import nthArg from '../src/nthArg';
describe('nthArg', () => {
const args = ['a', 'b', 'c', 'd'];
it('should create a function that returns its nth argument', () => {
const actual = lodashStable.map(args, (value, index) => {
const func = nthArg(index);
return func.apply(undefined, args);
});
expect(actual).toEqual(args);
});
it('should work with a negative `n`', () => {
const actual = lodashStable.map(lodashStable.range(1, args.length + 1), (n) => {
const func = nthArg(-n);
return func.apply(undefined, args);
});
expect(actual).toEqual(['d', 'c', 'b', 'a']);
});
it('should coerce `n` to an integer', () => {
let values = falsey;
let expected = lodashStable.map(values, stubA);
let actual = lodashStable.map(values, (n) => {
const func = n ? nthArg(n) : nthArg();
return func.apply(undefined, args);
});
expect(actual).toEqual(expected);
values = ['1', 1.6];
expected = lodashStable.map(values, stubB);
actual = lodashStable.map(values, (n) => {
const func = nthArg(n);
return func.apply(undefined, args);
});
expect(actual).toEqual(expected);
});
it('should return `undefined` for empty arrays', () => {
const func = nthArg(1);
expect(func()).toBe(undefined);
});
it('should return `undefined` for non-indexes', () => {
const values = [Infinity, args.length];
const expected = lodashStable.map(values, noop);
const actual = lodashStable.map(values, (n) => {
const func = nthArg(n);
return func.apply(undefined, args);
});
expect(actual).toEqual(expected);
});
});