Skip to content

Commit 2496ba5

Browse files
SEOKKAMONImanudeli
andauthored
test(react-query): improve branch coverage for useSuspenseInfiniteQuery skipToken error handling (#9114)
Co-authored-by: Jonghyeon Ko <manudeli.ko@gmail.com>
1 parent d0552af commit 2496ba5

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

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

+68
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,72 @@ describe('useSuspenseInfiniteQuery', () => {
4646
)
4747
consoleErrorSpy.mockRestore()
4848
})
49+
50+
it('should log an error when skipToken is used in development environment', () => {
51+
const envCopy = process.env.NODE_ENV
52+
process.env.NODE_ENV = 'development'
53+
54+
const consoleErrorSpy = vi
55+
.spyOn(console, 'error')
56+
.mockImplementation(() => undefined)
57+
const key = queryKey()
58+
59+
function Page() {
60+
useSuspenseInfiniteQuery({
61+
queryKey: key,
62+
queryFn: skipToken as any,
63+
initialPageParam: 1,
64+
getNextPageParam: () => 1,
65+
})
66+
67+
return null
68+
}
69+
70+
renderWithClient(
71+
queryClient,
72+
<React.Suspense fallback="Loading...">
73+
<Page />
74+
</React.Suspense>,
75+
)
76+
77+
expect(consoleErrorSpy).toHaveBeenCalledWith(
78+
'skipToken is not allowed for useSuspenseInfiniteQuery',
79+
)
80+
81+
consoleErrorSpy.mockRestore()
82+
process.env.NODE_ENV = envCopy
83+
})
84+
85+
it('should not log an error when skipToken is used in production environment', () => {
86+
const envCopy = process.env.NODE_ENV
87+
process.env.NODE_ENV = 'production'
88+
89+
const consoleErrorSpy = vi
90+
.spyOn(console, 'error')
91+
.mockImplementation(() => undefined)
92+
const key = queryKey()
93+
94+
function Page() {
95+
useSuspenseInfiniteQuery({
96+
queryKey: key,
97+
queryFn: skipToken as any,
98+
initialPageParam: 1,
99+
getNextPageParam: () => 1,
100+
})
101+
102+
return null
103+
}
104+
105+
renderWithClient(
106+
queryClient,
107+
<React.Suspense fallback="Loading...">
108+
<Page />
109+
</React.Suspense>,
110+
)
111+
112+
expect(consoleErrorSpy).not.toHaveBeenCalled()
113+
114+
consoleErrorSpy.mockRestore()
115+
process.env.NODE_ENV = envCopy
116+
})
49117
})

0 commit comments

Comments
 (0)