mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 20:43:30 +01:00
feat: override groupBy to return Collection (#10791)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -944,6 +944,29 @@ describe('union() tests', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('groupBy() tests', () => {
|
||||
test('returns a collection of grouped items', () => {
|
||||
const items = [
|
||||
{ name: 'Alice', age: 20 },
|
||||
{ name: 'Bob', age: 20 },
|
||||
{ name: 'Charlie', age: 30 },
|
||||
];
|
||||
|
||||
expect<Collection<number, typeof items>>(Collection.groupBy(items, (item) => item.age)).toStrictEqual(
|
||||
new Collection<number, typeof items>([
|
||||
[
|
||||
20,
|
||||
[
|
||||
{ name: 'Alice', age: 20 },
|
||||
{ name: 'Bob', age: 20 },
|
||||
],
|
||||
],
|
||||
[30, [{ name: 'Charlie', age: 30 }]],
|
||||
]),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('toReversed() tests', () => {
|
||||
test('reverses a collection', () => {
|
||||
const coll = createTestCollection();
|
||||
@@ -1152,5 +1175,8 @@ describe('subclassing tests', () => {
|
||||
test('Collection.combineEntries()', () => {
|
||||
expect(DerivedCollection.combineEntries([], Object)).toBeInstanceOf(DerivedCollection);
|
||||
});
|
||||
test('Collection.groupBy()', () => {
|
||||
expect(DerivedCollection.groupBy([], Object)).toBeInstanceOf(DerivedCollection);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user