Repository: discordjs/discord.js
File: packages/collection/__tests__/collection.test.ts (TypeScript)

Code before:
	test('returns false if no items pass the predicate', () => {
		expect(coll.some((v) => v > 3)).toBeFalsy();
	});
});

describe('sort() tests', () => {
	test('sort a collection in place', () => {
		const coll = createCollectionFrom(['a', 3], ['b', 2], ['c', 1]);
		expect([...coll.values()]).toStrictEqual([3, 2, 1]);
		coll.sort((a, b) => a - b);
		expect([...coll.values()]).toStrictEqual([1, 2, 3]);
	});

	describe('defaultSort', () => {
		test('stays the same if it is already sorted', () => {
			const coll = createTestCollection();
			expect(coll.sort()).toStrictEqual(coll);
		});

		test('stays the same if it is already sorted', () => {
			const coll = createCollectionFrom(['a', 5], ['b', 3], ['c', 1]);
			expect(coll.sort()).toStrictEqual(createCollectionFrom(['c', 1], ['b', 3], ['a', 5]));
		});

		describe('returns correct sort order for test values', () => {
			const defaultSort = Reflect.get(Collection, 'defaultSort') as (typeof Collection)['defaultSort'];
			const testDefaultSortOrder = (firstValue: any, secondValue: any, result: number) => {
				expect(defaultSort(firstValue, secondValue)).toStrictEqual(result);
				expect(defaultSort(secondValue, firstValue)).toStrictEqual(result ? result * -1 : 0);
			};

			test('correctly evaluates sort order of undefined', () => {
				testDefaultSortOrder(undefined, undefined, 0);
				testDefaultSortOrder(0, undefined, -1);
			});

			test('correctly evaluates numeric values stringwise', () => {
				testDefaultSortOrder(-1, -2, -1); // "-1" before "-2"
				testDefaultSortOrder(1, '1', 0); // "1" equal to "1"
				testDefaultSortOrder(1, '1.0', -1); // "1" before "1.0"
				testDefaultSortOrder(1.1, '1.1', 0); // "1.1" equal to "1.1"
				testDefaultSortOrder('01', 1, -1); // "01" before "1"
				testDefaultSortOrder(1, 1n, 0); // "1" equal to "1"
				testDefaultSortOrder(Number.NaN, 'NaN', 0); // "NaN" equal to "NaN"
			});

			test('evaluates object literals as equal', () => {
				testDefaultSortOrder({ a: 1 }, { b: 2 }, 0);
			});
		});
	});

Review comment (suggestion):
You should be able to do this
```suggestion
			const defaultSort = Collection['defaultSort'];
```

Code after:
describe('reduceRight() tests', () => {
	const coll = createTestCollection();

	test('throws if fn is not a function', () => {
		// @ts-expect-error: Invalid function
		expectInvalidFunctionError(() => coll.reduceRight());
		// @ts-expect-error: Invalid function
		expectInvalidFunctionError(() => coll.reduceRight(123), 123);
	});

	test('reduce collection into a single value with initial value', () => {
		const sum = coll.reduceRight((a, x) => a + x, 0);
		expect<number>(sum).toStrictEqual(6);
	});

	test('reduce collection into a single value without initial value', () => {
		const sum = coll.reduceRight((a, x) => a + x);
		expect<number>(sum).toStrictEqual(6);
	});

	test('reduce collection into a single value with different accumulator type', () => {
		const str = coll.reduceRight((a, x) => a.concat(x.toString()), '');
		expect<string>(str).toStrictEqual('321');
	});

	test('reduce empty collection with initial value', () => {
		const coll = createCollection();
		expect<number>(coll.reduceRight((a, x) => a + x, 0)).toStrictEqual(0);
	});

	test('reduce empty collection without initial value', () => {
		const coll = createCollection();
		expect(() => coll.reduceRight((a, x) => a + x)).toThrowError(
			new TypeError('Reduce of empty collection with no initial value'),
		);
	});
});

describe('reverse() tests', () => {
	test('reverts the collection', () => {
		const coll = createTestCollection();

		coll.reverse();

		expect([...coll.values()]).toStrictEqual([3, 2, 1]);
		expect([...coll.keys()]).toStrictEqual(['c', 'b', 'a']);
	});
});

describe('some() tests', () => {
	const coll = createTestCollection();