Skip to content

Commit defeee5

Browse files
Shiva953Jiralitekodiakhq[bot]
authoredNov 8, 2023
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>
1 parent 67a2538 commit defeee5

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed
 

‎packages/collection/__tests__/collection.test.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -828,9 +828,14 @@ describe('tap() tests', () => {
828828
});
829829

830830
describe('toJSON() tests', () => {
831-
test('it returns the values as an array', () => {
831+
test('it returns the entries of the collection', () => {
832832
const c = createTestCollection();
833-
expect(c.toJSON()).toStrictEqual([1, 2, 3]);
833+
834+
expect(c.toJSON()).toStrictEqual([
835+
['a', 1],
836+
['b', 2],
837+
['c', 3],
838+
]);
834839
});
835840
});
836841

‎packages/collection/src/collection.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ export class Collection<K, V> extends Map<K, V> {
933933

934934
public toJSON() {
935935
// toJSON is called recursively by JSON.stringify.
936-
return [...this.values()];
936+
return [...this.entries()];
937937
}
938938

939939
private static defaultSort<V>(firstValue: V, secondValue: V): number {

0 commit comments

Comments
 (0)
Please sign in to comment.