From dd7724a394cf46746208b233d6cf719acad4e083 Mon Sep 17 00:00:00 2001 From: Giulio Canti Date: Fri, 17 Jan 2025 09:45:31 +0100 Subject: [PATCH] refactor Chunk.toArray tests for clarity and coverage (#4283) --- packages/effect/test/Chunk.test.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/effect/test/Chunk.test.ts b/packages/effect/test/Chunk.test.ts index ad08940b02b..cf6225942e4 100644 --- a/packages/effect/test/Chunk.test.ts +++ b/packages/effect/test/Chunk.test.ts @@ -134,9 +134,23 @@ describe("Chunk", () => { expect(Chunk.empty().pipe(Chunk.append(1))).toEqual(Chunk.make(1)) }) - it("toArray", () => { - expect(Chunk.toArray(Chunk.empty())).toStrictEqual([]) - expect(Chunk.toArray(Chunk.make(1, 2, 3))).toStrictEqual([1, 2, 3]) + describe("toArray", () => { + it("should return an empty array for an empty chunk", () => { + expect(Chunk.toArray(Chunk.empty())).toEqual([]) + }) + + it("should return an array with the elements of the chunk", () => { + expect(Chunk.toArray(Chunk.make(1, 2, 3))).toEqual([1, 2, 3]) + }) + + it("should not affect the original chunk when the array is mutated", () => { + const chunk = Chunk.make(1, 2, 3) + const arr = Chunk.toArray(chunk) + // mutate the array + arr[1] = 4 + // the chunk should not be affected + expect(Chunk.toArray(chunk)).toStrictEqual([1, 2, 3]) + }) }) describe("toReadonlyArray", () => {