Skip to content

Commit

Permalink
Add test to ensure configured auto dispose timer is honored
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Dec 11, 2023
1 parent fc757b1 commit 51df7c2
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/react/query-preloader/__tests__/createQueryPreloader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,40 @@ test("Auto disposes of the query ref if not retained within the given time", asy
jest.useRealTimers();
});

test("Honors configured auto dispose timer on the client", async () => {
jest.useFakeTimers();
const { query, mocks } = useSimpleCase();
const client = new ApolloClient({
cache: new InMemoryCache(),
link: new MockLink(mocks),
defaultOptions: {
react: {
suspense: {
autoDisposeTimeoutMs: 5000,
},
},
},
});

const preloadQuery = createQueryPreloader(client);

const queryRef = preloadQuery(query);

// We don't start the dispose timer until the promise is initially resolved
// so we need to wait for it
jest.advanceTimersByTime(20);
await queryRef.toPromise();
jest.advanceTimersByTime(5_000);

const internalQueryRef = unwrapQueryRef(queryRef);

expect(internalQueryRef.disposed).toBe(true);
expect(client.getObservableQueries().size).toBe(0);
expect(client).not.toHaveSuspenseCacheEntryUsing(query);

jest.useRealTimers();
});

test.todo(
"useReadQuery auto-retains the queryRef and disposes of it when unmounted"
);
Expand Down

0 comments on commit 51df7c2

Please sign in to comment.