mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 09: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>
38 lines
1.5 KiB
JavaScript
38 lines
1.5 KiB
JavaScript
import lodashStable from 'lodash';
|
|
import { _, MAX_SAFE_INTEGER } from './utils';
|
|
|
|
describe('startsWith and endsWith', () => {
|
|
lodashStable.each(['startsWith', 'endsWith'], (methodName) => {
|
|
const func = _[methodName];
|
|
const isStartsWith = methodName === 'startsWith';
|
|
|
|
const string = 'abc';
|
|
const chr = isStartsWith ? 'a' : 'c';
|
|
|
|
it(`\`_.${methodName}\` should coerce \`string\` to a string`, () => {
|
|
expect(func(Object(string), chr)).toBe(true);
|
|
expect(func({ toString: lodashStable.constant(string) }, chr)).toBe(true);
|
|
});
|
|
|
|
it(`\`_.${methodName}\` should coerce \`target\` to a string`, () => {
|
|
expect(func(string, Object(chr))).toBe(true);
|
|
expect(func(string, { toString: lodashStable.constant(chr) })).toBe(true);
|
|
});
|
|
|
|
it(`\`_.${methodName}\` should coerce \`position\` to a number`, () => {
|
|
const position = isStartsWith ? 1 : 2;
|
|
|
|
expect(func(string, 'b', Object(position))).toBe(true);
|
|
expect(
|
|
func(string, 'b', { toString: lodashStable.constant(String(position)) }),
|
|
).toBeTruthy();
|
|
});
|
|
|
|
it('should return `true` when `target` is an empty string regardless of `position`', () => {
|
|
const positions = [-Infinity, NaN, -3, -1, 0, 1, 2, 3, 5, MAX_SAFE_INTEGER, Infinity];
|
|
|
|
expect(lodashStable.every(positions, (position) => func(string, '', position)));
|
|
});
|
|
});
|
|
});
|