mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 11:33:30 +01:00
feat: align some methods with the Change By Copy proposal (#9207)
BREAKING CHANGE: The `sorted` method has been renamed to `toSorted`
This commit is contained in:
@@ -754,14 +754,6 @@ describe('sort() tests', () => {
|
||||
expect([...coll.values()]).toStrictEqual([1, 2, 3]);
|
||||
});
|
||||
|
||||
test('sort a collection', () => {
|
||||
const coll = createCollectionFrom(['a', 3], ['b', 2], ['c', 1]);
|
||||
expect([...coll.values()]).toStrictEqual([3, 2, 1]);
|
||||
const sorted = coll.sorted((a, b) => a - b);
|
||||
expect([...coll.values()]).toStrictEqual([3, 2, 1]);
|
||||
expect([...sorted.values()]).toStrictEqual([1, 2, 3]);
|
||||
});
|
||||
|
||||
describe('defaultSort', () => {
|
||||
test('stays the same if it is already sorted', () => {
|
||||
const coll = createTestCollection();
|
||||
@@ -855,6 +847,48 @@ describe('union() tests', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('toReversed() tests', () => {
|
||||
test('reverses a collection', () => {
|
||||
const coll = createTestCollection();
|
||||
const reversed = coll.toReversed();
|
||||
expect([...reversed.entries()]).toStrictEqual([
|
||||
['c', 3],
|
||||
['b', 2],
|
||||
['a', 1],
|
||||
]);
|
||||
});
|
||||
|
||||
test('does not the modify original collection', () => {
|
||||
const coll = createTestCollection();
|
||||
const originalEntries = [...coll.entries()];
|
||||
const reversed = coll.toReversed();
|
||||
|
||||
expect(reversed).not.toBe(coll);
|
||||
expect([...coll.entries()]).toStrictEqual(originalEntries);
|
||||
});
|
||||
});
|
||||
|
||||
describe('toSorted() tests', () => {
|
||||
test('sorts a collection', () => {
|
||||
const coll = createCollectionFrom(['a', 3], ['b', 2], ['c', 1]);
|
||||
const sorted = coll.toSorted((a, b) => a - b);
|
||||
expect([...sorted.entries()]).toStrictEqual([
|
||||
['c', 1],
|
||||
['b', 2],
|
||||
['a', 3],
|
||||
]);
|
||||
});
|
||||
|
||||
test('does not modify the original collection', () => {
|
||||
const coll = createCollectionFrom(['a', 3], ['b', 2], ['c', 1]);
|
||||
const originalEntries = [...coll.entries()];
|
||||
const sorted = coll.toSorted();
|
||||
|
||||
expect(sorted).not.toBe(coll);
|
||||
expect([...coll.entries()]).toStrictEqual(originalEntries);
|
||||
});
|
||||
});
|
||||
|
||||
describe('random thisArg tests', () => {
|
||||
const coll = createCollectionFrom(['a', 3], ['b', 2], ['c', 1]) as Collection<string, unknown>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user