Skip to content

Commit 2a62ea1

Browse files
SEOKKAMONImanudeli
andauthored
test(react-query): improve branch coverage for useSuspenseQuery skipToken error handling (#9112)
Co-authored-by: Jonghyeon Ko <[email protected]>
1 parent b1cdbc3 commit 2a62ea1

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

packages/react-query/src/__tests__/useSuspenseQuery.test.tsx

+64
Original file line numberDiff line numberDiff line change
@@ -967,4 +967,68 @@ describe('useSuspenseQuery', () => {
967967

968968
expect(count).toBeGreaterThanOrEqual(3)
969969
})
970+
971+
it('should log an error when skipToken is used in development environment', () => {
972+
const envCopy = process.env.NODE_ENV
973+
process.env.NODE_ENV = 'development'
974+
975+
const consoleErrorSpy = vi
976+
.spyOn(console, 'error')
977+
.mockImplementation(() => undefined)
978+
const key = queryKey()
979+
980+
function Page() {
981+
useSuspenseQuery({
982+
queryKey: key,
983+
queryFn: skipToken as any,
984+
})
985+
986+
return null
987+
}
988+
989+
renderWithClient(
990+
queryClient,
991+
<React.Suspense fallback="Loading...">
992+
<Page />
993+
</React.Suspense>,
994+
)
995+
996+
expect(consoleErrorSpy).toHaveBeenCalledWith(
997+
'skipToken is not allowed for useSuspenseQuery',
998+
)
999+
1000+
consoleErrorSpy.mockRestore()
1001+
process.env.NODE_ENV = envCopy
1002+
})
1003+
1004+
it('should not log an error when skipToken is used in production environment', () => {
1005+
const envCopy = process.env.NODE_ENV
1006+
process.env.NODE_ENV = 'production'
1007+
1008+
const consoleErrorSpy = vi
1009+
.spyOn(console, 'error')
1010+
.mockImplementation(() => undefined)
1011+
const key = queryKey()
1012+
1013+
function Page() {
1014+
useSuspenseQuery({
1015+
queryKey: key,
1016+
queryFn: skipToken as any,
1017+
})
1018+
1019+
return null
1020+
}
1021+
1022+
renderWithClient(
1023+
queryClient,
1024+
<React.Suspense fallback="Loading...">
1025+
<Page />
1026+
</React.Suspense>,
1027+
)
1028+
1029+
expect(consoleErrorSpy).not.toHaveBeenCalled()
1030+
1031+
consoleErrorSpy.mockRestore()
1032+
process.env.NODE_ENV = envCopy
1033+
})
9701034
})

0 commit comments

Comments
 (0)