MCPcopy Index your code
hub / github.com/coder/coder / testPrefetch

Function testPrefetch

site/src/hooks/usePaginatedQuery.test.ts:115–138  ·  view source on GitHub ↗
(
			startingPage: number,
			targetPage: number,
			shouldMatch: boolean,
		)

Source from the content-addressed store, hash-verified

113 };
114
115 const testPrefetch = async (
116 startingPage: number,
117 targetPage: number,
118 shouldMatch: boolean,
119 ) => {
120 // Have to reinitialize mock function every call to avoid false positives
121 // from shared mutable tracking state
122 const mockQueryFn = vi.fn(mockQueryFnImplementation);
123 const { result } = await render(
124 { queryKey: mockQueryKey, queryFn: mockQueryFn },
125 `/?page=${startingPage}`,
126 );
127
128 const pageMatcher = expect.objectContaining({ pageNumber: targetPage });
129 if (shouldMatch) {
130 await waitFor(() => expect(result.current.totalRecords).toBeDefined());
131 await waitFor(() =>
132 expect(mockQueryFn).toHaveBeenCalledWith(pageMatcher),
133 );
134 } else {
135 await new Promise((resolve) => setTimeout(resolve, 10));
136 expect(mockQueryFn).not.toHaveBeenCalledWith(pageMatcher);
137 }
138 };
139
140 it("Prefetches the previous page if it exists", async () => {
141 await testPrefetch(2, 1, true);

Callers 1

Calls 1

renderFunction · 0.70

Tested by

no test coverage detected