From 3fdc3816b18dc8fff7e6f966e399a625e4b7a9e7 Mon Sep 17 00:00:00 2001 From: Mike Ciesielka Date: Mon, 2 Sep 2024 15:28:51 -0400 Subject: [PATCH] Write failing test --- .../hooks/__tests__/useFragment.test.tsx | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/react/hooks/__tests__/useFragment.test.tsx b/src/react/hooks/__tests__/useFragment.test.tsx index f58ef9aaa6d..046c1c538c9 100644 --- a/src/react/hooks/__tests__/useFragment.test.tsx +++ b/src/react/hooks/__tests__/useFragment.test.tsx @@ -260,6 +260,45 @@ describe("useFragment", () => { "item 4", ]); + // set Item #2 back to its original value + act(() => { + cache.writeFragment({ + fragment: ItemFragment, + data: { + __typename: "Item", + id: 2, + text: "Item #2", + }, + }); + }); + + await waitFor(() => { + expect(getItemTexts()).toEqual([ + "Item #1", + "Item #2", + "Item #3 from cache.modify", + "Item #4 updated", + "Item #5", + ]); + }); + + expect(renders).toEqual([ + "list", + "item 1", + "item 2", + "item 5", + "item 2", + "list", + "item 1", + "item 2", + "item 3", + "item 4", + "item 5", + "item 4", + // Only the second item should have re-rendered. + "item 2", + ]); + expect(cache.extract()).toEqual({ "Item:1": { __typename: "Item", @@ -268,7 +307,7 @@ describe("useFragment", () => { "Item:2": { __typename: "Item", id: 2, - text: "Item #2 updated", + text: "Item #2", }, "Item:3": { __typename: "Item",