feat: return entries instead of values in toJSON method (#9345)

* feat(collection): return entries instead of values in toJSON method

* test: adjust test

---------

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Neutron
2023-11-08 06:58:27 +05:30
committed by GitHub
parent 67a2538b4d
commit defeee5eec
2 changed files with 8 additions and 3 deletions

View File

@@ -828,9 +828,14 @@ describe('tap() tests', () => {
}); });
describe('toJSON() tests', () => { describe('toJSON() tests', () => {
test('it returns the values as an array', () => { test('it returns the entries of the collection', () => {
const c = createTestCollection(); const c = createTestCollection();
expect(c.toJSON()).toStrictEqual([1, 2, 3]);
expect(c.toJSON()).toStrictEqual([
['a', 1],
['b', 2],
['c', 3],
]);
}); });
}); });

View File

@@ -933,7 +933,7 @@ export class Collection<K, V> extends Map<K, V> {
public toJSON() { public toJSON() {
// toJSON is called recursively by JSON.stringify. // toJSON is called recursively by JSON.stringify.
return [...this.values()]; return [...this.entries()];
} }
private static defaultSort<V>(firstValue: V, secondValue: V): number { private static defaultSort<V>(firstValue: V, secondValue: V): number {