Skip to content

Commit d7d766e

Browse files
authored
chore: fix test warnings (TanStack#2070)
* chore: fix eslint warnings by including refetch in the dependency array the refetch function is stable * chore: mockConsoleError for tests that expect errors to be thrown to avoid error output on the console during tests
1 parent 6ee897c commit d7d766e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/core/tests/queryObserver.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ describe('queryObserver', () => {
241241
})
242242

243243
test('should always run the selector again if selector throws an error', async () => {
244+
const consoleMock = mockConsoleError()
244245
const key = queryKey()
245246
const results: QueryObserverResult[] = []
246247
const select = () => {
@@ -284,6 +285,7 @@ describe('queryObserver', () => {
284285
isFetching: false,
285286
data: undefined,
286287
})
288+
consoleMock.mockRestore()
287289
})
288290

289291
test('should structurally share the selector', async () => {

src/react/tests/useQuery.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3611,14 +3611,16 @@ describe('useQuery', () => {
36113611

36123612
states.push(state)
36133613

3614+
const { refetch } = state
3615+
36143616
React.useEffect(() => {
36153617
setActTimeout(() => {
3616-
state.refetch()
3618+
refetch()
36173619
}, 0)
36183620
setActTimeout(() => {
36193621
queryClient.resetQueries(key)
36203622
}, 50)
3621-
}, [])
3623+
}, [refetch])
36223624

36233625
return null
36243626
}

0 commit comments

Comments
 (0)