@@ -46,4 +46,72 @@ describe('useSuspenseInfiniteQuery', () => {
46
46
)
47
47
consoleErrorSpy . mockRestore ( )
48
48
} )
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
+ } )
49
117
} )
0 commit comments