Skip to content

Commit

Permalink
Write failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
maciesielka committed Sep 2, 2024
1 parent 36d2cae commit 3fdc381
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/react/hooks/__tests__/useFragment.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -268,7 +307,7 @@ describe("useFragment", () => {
"Item:2": {
__typename: "Item",
id: 2,
text: "Item #2 updated",
text: "Item #2",
},
"Item:3": {
__typename: "Item",
Expand Down

0 comments on commit 3fdc381

Please sign in to comment.