@@ -174,3 +174,131 @@ test('warns only for reducer if everything is missing', async () => {
174
174
'Error: No data found at `state.api1`. Did you forget to add the reducer to the store?'
175
175
)
176
176
} )
177
+
178
+ describe ( '`console.error` on unhandled errors during `initiate`' , ( ) => {
179
+ test ( 'error thrown in `baseQuery`' , async ( ) => {
180
+ const api = createApi ( {
181
+ baseQuery ( ) {
182
+ throw new Error ( 'this was kinda expected' )
183
+ } ,
184
+ endpoints : ( build ) => ( {
185
+ baseQuery : build . query < any , void > ( { query ( ) { } } ) ,
186
+ } ) ,
187
+ } )
188
+ const store = configureStore ( {
189
+ reducer : { [ api . reducerPath ] : api . reducer } ,
190
+ middleware : ( gdm ) => gdm ( ) . concat ( api . middleware ) ,
191
+ } )
192
+ await store . dispatch ( api . endpoints . baseQuery . initiate ( ) )
193
+
194
+ expect ( getLog ( ) . log )
195
+ . toBe ( `An unhandled error occured processing a request for the endpoint "baseQuery".
196
+ In the case of an unhandled error, no tags will be "provided" or "invalidated". [Error: this was kinda expected]` )
197
+ } )
198
+
199
+ test ( 'error thrown in `queryFn`' , async ( ) => {
200
+ const api = createApi ( {
201
+ baseQuery ( ) {
202
+ return { data : { } }
203
+ } ,
204
+ endpoints : ( build ) => ( {
205
+ queryFn : build . query < any , void > ( {
206
+ queryFn ( ) {
207
+ throw new Error ( 'this was kinda expected' )
208
+ } ,
209
+ } ) ,
210
+ } ) ,
211
+ } )
212
+ const store = configureStore ( {
213
+ reducer : { [ api . reducerPath ] : api . reducer } ,
214
+ middleware : ( gdm ) => gdm ( ) . concat ( api . middleware ) ,
215
+ } )
216
+ await store . dispatch ( api . endpoints . queryFn . initiate ( ) )
217
+
218
+ expect ( getLog ( ) . log )
219
+ . toBe ( `An unhandled error occured processing a request for the endpoint "queryFn".
220
+ In the case of an unhandled error, no tags will be "provided" or "invalidated". [Error: this was kinda expected]` )
221
+ } )
222
+
223
+ test ( 'error thrown in `transformResponse`' , async ( ) => {
224
+ const api = createApi ( {
225
+ baseQuery ( ) {
226
+ return { data : { } }
227
+ } ,
228
+ endpoints : ( build ) => ( {
229
+ transformRspn : build . query < any , void > ( {
230
+ query ( ) { } ,
231
+ transformResponse ( ) {
232
+ throw new Error ( 'this was kinda expected' )
233
+ } ,
234
+ } ) ,
235
+ } ) ,
236
+ } )
237
+ const store = configureStore ( {
238
+ reducer : { [ api . reducerPath ] : api . reducer } ,
239
+ middleware : ( gdm ) => gdm ( ) . concat ( api . middleware ) ,
240
+ } )
241
+ await store . dispatch ( api . endpoints . transformRspn . initiate ( ) )
242
+
243
+ expect ( getLog ( ) . log )
244
+ . toBe ( `An unhandled error occured processing a request for the endpoint "transformRspn".
245
+ In the case of an unhandled error, no tags will be "provided" or "invalidated". [Error: this was kinda expected]` )
246
+ } )
247
+
248
+ test ( '`fetchBaseQuery`: error thrown in `prepareHeaders`' , async ( ) => {
249
+ const api = createApi ( {
250
+ baseQuery : fetchBaseQuery ( {
251
+ baseUrl : 'http://example.com' ,
252
+ prepareHeaders ( ) {
253
+ throw new Error ( 'this was kinda expected' )
254
+ } ,
255
+ } ) ,
256
+ endpoints : ( build ) => ( {
257
+ prep : build . query < any , void > ( {
258
+ query ( ) {
259
+ return '/success'
260
+ } ,
261
+ } ) ,
262
+ } ) ,
263
+ } )
264
+ const store = configureStore ( {
265
+ reducer : { [ api . reducerPath ] : api . reducer } ,
266
+ middleware : ( gdm ) => gdm ( ) . concat ( api . middleware ) ,
267
+ } )
268
+ await store . dispatch ( api . endpoints . prep . initiate ( ) )
269
+
270
+ expect ( getLog ( ) . log )
271
+ . toBe ( `An unhandled error occured processing a request for the endpoint "prep".
272
+ In the case of an unhandled error, no tags will be "provided" or "invalidated". [Error: this was kinda expected]` )
273
+ } )
274
+
275
+ test ( '`fetchBaseQuery`: error thrown in `validateStatus`' , async ( ) => {
276
+ const api = createApi ( {
277
+ baseQuery : fetchBaseQuery ( {
278
+ baseUrl : 'http://example.com' ,
279
+ } ) ,
280
+ endpoints : ( build ) => ( {
281
+ val : build . query < any , void > ( {
282
+ query ( ) {
283
+ return {
284
+ url :'/success' ,
285
+
286
+ validateStatus ( ) {
287
+ throw new Error ( 'this was kinda expected' )
288
+ } ,
289
+ }
290
+ } ,
291
+ } ) ,
292
+ } ) ,
293
+ } )
294
+ const store = configureStore ( {
295
+ reducer : { [ api . reducerPath ] : api . reducer } ,
296
+ middleware : ( gdm ) => gdm ( ) . concat ( api . middleware ) ,
297
+ } )
298
+ await store . dispatch ( api . endpoints . val . initiate ( ) )
299
+
300
+ expect ( getLog ( ) . log )
301
+ . toBe ( `An unhandled error occured processing a request for the endpoint "val".
302
+ In the case of an unhandled error, no tags will be "provided" or "invalidated". [Error: this was kinda expected]` )
303
+ } )
304
+ } )
0 commit comments