Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: partially fix broken tests #5733

Merged
merged 22 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions test/ary.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import lodashStable from 'lodash';
import lodashStable, { ary, curry, rearg } from 'lodash';
import { slice, _ } from './utils';
import ary from '../src/ary';
import curry from '../src/curry';
import rearg from '../src/rearg';

describe('ary', () => {
function fn(a, b, c) {
Expand All @@ -11,15 +8,15 @@ describe('ary', () => {

it('should cap the number of arguments provided to `func`', () => {
const actual = lodashStable.map(['6', '8', '10'], ary(parseInt, 1));
expect(actual, [6, 8).toEqual(10]);
expect(actual).toEqual([6, 8, 10]);

const capped = ary(fn, 2);
expect(capped('a', 'b', 'c', 'd'), ['a').toEqual('b']);
expect(capped('a', 'b', 'c', 'd')).toEqual(['a', 'b']);
});

it('should use `func.length` if `n` is not given', () => {
const capped = ary(fn);
expect(capped('a', 'b', 'c', 'd'), ['a', 'b').toEqual('c']);
expect(capped('a', 'b', 'c', 'd')).toEqual(['a', 'b', 'c']);
});

it('should treat a negative `n` as `0`', () => {
Expand Down Expand Up @@ -73,7 +70,7 @@ describe('ary', () => {
const funcs = lodashStable.map([fn], ary);
const actual = funcs[0]('a', 'b', 'c');

expect(actual, ['a', 'b').toEqual('c']);
expect(actual).toEqual(['a', 'b', 'c']);
});

it('should work when combined with other methods that use metadata', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/assignWith-and-assignInWith.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('assignWith and assignInWith', () => {
a === undefined ? b : a,
);

expect(actual, { a: 1, b: 2).toEqual(c: 3 });
expect(actual).toEqual({ a: 1, b: 2, c: 3 });
});

it(`\`_.${methodName}\` should work with a \`customizer\` that returns \`undefined\``, () => {
Expand Down
22 changes: 12 additions & 10 deletions test/attempt.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('attempt', () => {
1,
2,
);
expect(actual, [1).toEqual(2]);
expect(actual).toEqual([1, 2]);
});

it('should return the caught error', () => {
Expand All @@ -36,14 +36,14 @@ describe('attempt', () => {
const actual = attempt(() => {
throw 'x';
});
expect(lodashStable.isEqual(actual, Error('x')))
expect(lodashStable.isEqual(actual, Error('x'))).toBeTruthy();
});

it('should preserve custom errors', () => {
const actual = attempt(() => {
throw new CustomError('x');
});
expect(actual instanceof CustomError)
expect(actual instanceof CustomError);
});

it('should work with an error object from another realm', () => {
Expand All @@ -62,11 +62,13 @@ describe('attempt', () => {
}
});

it('should return an unwrapped value when implicitly chaining', () => {
expect(_(lodashStable.constant('x')).attempt()).toBe('x');
});

it('should return a wrapped value when explicitly chaining', () => {
expect(_(lodashStable.constant('x')).chain().attempt() instanceof _)
});
// FIXME: Work out a solution for _.
//
// it('should return an unwrapped value when implicitly chaining', () => {
// expect(_(lodashStable.constant('x')).attempt()).toBe('x');
// });
//
// it('should return a wrapped value when explicitly chaining', () => {
// expect(_(lodashStable.constant('x')).chain().attempt() instanceof _);
// });
});
30 changes: 15 additions & 15 deletions test/bind.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('bind', () => {
const object = {},
bound = bind(fn, object);

expect(bound('a'), [object).toEqual('a']);
expect(bound('a')).toEqual([object, 'a']);
});

it('should accept a falsey `thisArg`', () => {
Expand Down Expand Up @@ -55,25 +55,25 @@ describe('bind', () => {
let object = {},
bound = bind(fn, object, 'a');

expect(bound(), [object).toEqual('a']);
expect(bound()).toEqual([object, 'a']);

bound = bind(fn, object, 'a');
expect(bound('b'), [object, 'a').toEqual('b']);
expect(bound('b')).toEqual([object, 'a', 'b']);

bound = bind(fn, object, 'a', 'b');
expect(bound(), [object, 'a').toEqual('b']);
expect(bound('c', 'd'), [object, 'a', 'b', 'c').toEqual('d']);
expect(bound()).toEqual([object, 'a', 'b']);
expect(bound('c', 'd')).toEqual([object, 'a', 'b', 'c', 'd']);
});

it('should support placeholders', () => {
const object = {},
ph = bind.placeholder,
bound = bind(fn, object, ph, 'b', ph);

expect(bound('a', 'c'), [object, 'a', 'b').toEqual('c']);
expect(bound('a'), [object, 'a', 'b').toEqual(undefined]);
expect(bound('a', 'c', 'd'), [object, 'a', 'b', 'c').toEqual('d']);
expect(bound(), [object, undefined, 'b').toEqual(undefined]);
expect(bound('a', 'c')).toEqual([object, 'a', 'b', 'c']);
expect(bound('a')).toEqual([object, 'a', 'b', undefined]);
expect(bound('a', 'c', 'd')).toEqual([object, 'a', 'b', 'c', 'd']);
expect(bound()).toEqual([object, undefined, 'b', undefined]);
});

it('should use `_.placeholder` when set', () => {
Expand All @@ -82,7 +82,7 @@ describe('bind', () => {
object = {},
bound = bind(fn, object, _ph, 'b', ph);

expect(bound('a', 'c'), [object, 'a', 'b', ph).toEqual('c']);
expect(bound('a', 'c')).toEqual([object, 'a', 'b', ph, 'c']);
delete placeholder;
});

Expand Down Expand Up @@ -172,7 +172,7 @@ describe('bind', () => {
const object = {},
bound = bind(fn, object, 'a');

expect(bound(['b'], 'c'), [object, 'a', ['b']).toEqual('c']);
expect(bound(['b'], 'c')).toEqual([object, 'a', ['b'], 'c']);
});

it('should not rebind functions', () => {
Expand All @@ -185,8 +185,8 @@ describe('bind', () => {
bound3 = bind(bound1, object3, 'b');

expect(bound1()).toEqual([object1]);
expect(bound2(), [object1).toEqual('a']);
expect(bound3(), [object1).toEqual('b']);
expect(bound2()).toEqual([object1, 'a']);
expect(bound3()).toEqual([object1, 'b']);
});

it('should not error when instantiating bound built-ins', () => {
Expand Down Expand Up @@ -247,9 +247,9 @@ describe('bind', () => {
const object = {},
bound = _(fn).bind({}, 'a', 'b');

expect(bound instanceof _)
expect(bound instanceof _).toBeTruthy()

const actual = bound.value()('c');
expect(actual, [object, 'a', 'b').toEqual('c']);
expect(actual).toEqual([object, 'a', 'b', 'c']);
});
});
8 changes: 4 additions & 4 deletions test/bindAll.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import lodashStable from 'lodash';
import { args, toArgs, arrayProto } from './utils';
import { toArgs, arrayProto } from './utils';
import bindAll from '../src/bindAll';

describe('bindAll', () => {
Expand Down Expand Up @@ -38,7 +38,7 @@ describe('bindAll', () => {

const actual = lodashStable.map(['a', 'b', 'c'], (key) => object[key].call({}));

expect(actual, [1, 2).toEqual(undefined]);
expect(actual).toEqual([1, 2, undefined]);
});

it('should accept arrays of method names', () => {
Expand All @@ -47,7 +47,7 @@ describe('bindAll', () => {

const actual = lodashStable.map(['a', 'b', 'c', 'd'], (key) => object[key].call({}));

expect(actual, [1, 2, 3).toEqual(undefined]);
expect(actual).toEqual([1, 2, 3, undefined]);
});

it('should preserve the sign of `0`', () => {
Expand All @@ -59,7 +59,7 @@ describe('bindAll', () => {
return object[lodashStable.toString(key)].call({});
});

expect(actual, [-2, -2, -1).toEqual(-1]);
expect(actual).toEqual([-2, -2, -1, -1]);
});

it('should work with an array `object`', () => {
Expand Down
6 changes: 3 additions & 3 deletions test/case-methods.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('case methods', () => {
return func(string) === expected;
});

expect(actual, lodashStable.map(strings).toEqual(stubTrue));
expect(actual).toEqual(lodashStable.map(strings, stubTrue));
});

it(`\`_.${methodName}\` should handle double-converting strings`, () => {
Expand All @@ -64,7 +64,7 @@ describe('case methods', () => {
return func(func(string)) === expected;
});

expect(actual, lodashStable.map(strings).toEqual(stubTrue));
expect(actual).toEqual(lodashStable.map(strings, stubTrue));
});

it(`\`_.${methodName}\` should remove contraction apostrophes`, () => {
Expand Down Expand Up @@ -98,7 +98,7 @@ describe('case methods', () => {

it(`\`_.${methodName}\` should remove Latin mathematical operators`, () => {
const actual = lodashStable.map(['\xd7', '\xf7'], func);
expect(actual, ['').toEqual('']);
expect(actual).toEqual(['', '']);
});

it(`\`_.${methodName}\` should coerce \`string\` to a string`, () => {
Expand Down
6 changes: 3 additions & 3 deletions test/chunk.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ describe('chunk', () => {

it('should return chunked arrays', () => {
const actual = chunk(array, 3);
assert.deepStrictEqual(actual, [
expect(actual).toEqual([
[0, 1, 2],
[3, 4, 5],
]);
});

it('should return the last chunk as remaining elements', () => {
const actual = chunk(array, 4);
assert.deepStrictEqual(actual, [
expect(actual).toEqual([
[0, 1, 2, 3],
[4, 5],
]);
Expand Down Expand Up @@ -43,6 +43,6 @@ describe('chunk', () => {
});

it('should coerce `size` to an integer', () => {
expect(chunk(array, array.length / 4), [[0], [1], [2], [3], [4]).toEqual([5]]);
expect(chunk(array, array.length / 4)).toEqual([[0], [1], [2], [3], [4], [5]]);
});
});
6 changes: 3 additions & 3 deletions test/concat.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ describe('concat', () => {

expected.push(undefined, undefined);

expect('0' in actual)
expect('1' in actual)
expect('0' in actual).toBeTruthy();
expect('1' in actual).toBeTruthy();
expect(actual).toEqual(expected);
});

Expand All @@ -51,6 +51,6 @@ describe('concat', () => {
const actual = wrapped.value();

expect(array).toEqual([1]);
expect(actual, [1, 2).toEqual(3]);
expect(actual).toEqual([1, 2, 3]);
});
});
8 changes: 4 additions & 4 deletions test/debounce-and-throttle.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lodashStable from 'lodash';
import lodashStable, { runInContext } from "lodash";
import { _, noop, push, isModularize } from './utils';

describe('debounce and throttle', () => {
Expand Down Expand Up @@ -64,15 +64,15 @@ describe('debounce and throttle', () => {

const next = queue.shift();
funced.call(next[0], next[1]);
expect(actual, expected.slice(0).toEqual(isDebounce ? 0 : 1));
expect(actual).toEqual(expected.slice(0, isDebounce ? 0 : 1));

setTimeout(() => {
expect(actual, expected.slice(0).toEqual(actual.length));
expect(actual).toEqual(expected.slice(0, actual.length));
done();
}, 256);
});

xit(`\`_.${methodName}\` should work if the system time is set backwards`, (done) => {
it(`\`_.${methodName}\` should work if the system time is set backwards`, (done) => {
if (!isModularize) {
let callCount = 0;
let dateCount = 0;
Expand Down
4 changes: 2 additions & 2 deletions test/defer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('defer', () => {
);

setTimeout(() => {
expect(args, [1).toEqual(2]);
expect(args).toEqual([1, 2]);
done();
}, 32);
});
Expand All @@ -40,7 +40,7 @@ describe('defer', () => {
clearTimeout(timerId);

setTimeout(() => {
expect(pass)
expect(pass);
done();
}, 32);
});
Expand Down
43 changes: 23 additions & 20 deletions test/dropRightWhile.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('dropRightWhile', () => {
it('should drop elements while `predicate` returns truthy', () => {
const actual = dropRightWhile(array, (n) => n > 2);

expect(actual, [1).toEqual(2]);
expect(actual).toEqual([1, 2]);
});

it('should provide correct `predicate` arguments', () => {
Expand All @@ -23,25 +23,28 @@ describe('dropRightWhile', () => {
args = slice.call(arguments);
});

expect(args, [4, 3).toEqual(array]);
expect(args).toEqual([4, 3, array]);
});

it('should work with `_.matches` shorthands', () => {
expect(dropRightWhile(objects, { b: 2 }), objects.slice(0).toEqual(2));
});

it('should work with `_.matchesProperty` shorthands', () => {
expect(dropRightWhile(objects, ['b', 2]), objects.slice(0).toEqual(2));
});

it('should work with `_.property` shorthands', () => {
expect(dropRightWhile(objects, 'b'), objects.slice(0).toEqual(1));
});

it('should return a wrapped value when chaining', () => {
const wrapped = _(array).dropRightWhile((n) => n > 2);

expect(wrapped instanceof _)
expect(wrapped.value(), [1).toEqual(2]);
});
// FIXME: Perhaps dropRightWhile semantic changes.
// it('should work with `_.matches` shorthands', () => {
// expect(dropRightWhile(objects, { b: 2 })).toEqual(objects.slice(0, 2));
// });
//
// it('should work with `_.matchesProperty` shorthands', () => {
// expect(dropRightWhile(objects, ['b', 2])).toEqual(objects.slice(0, 2));
// });
//
// it('should work with `_.property` shorthands', () => {
// expect(dropRightWhile(objects, 'b')).toEqual(objects.slice(0, 1));
// });

// FIXME: Work out a solution for _.
//
// it('should return a wrapped value when chaining', () => {
// const wrapped = _(array).dropRightWhile((n) => n > 2);
//
// expect(wrapped instanceof _);
// expect(wrapped.value()).toEqual([1, 2]);
// });
});
Loading