@@ -198,11 +198,8 @@ describe('hooks tests', () => {
198
198
const [ value , setValue ] = React . useState ( 0 )
199
199
getRenderCount = useRenderCounter ( )
200
200
201
- const {
202
- isLoading,
203
- isFetching,
204
- refetch,
205
- } = api . endpoints . getUser . useQuery ( 22 , { skip : value < 1 } )
201
+ const { isLoading, isFetching, refetch } =
202
+ api . endpoints . getUser . useQuery ( 22 , { skip : value < 1 } )
206
203
refetchMe = refetch
207
204
return (
208
205
< div >
@@ -259,13 +256,10 @@ describe('hooks tests', () => {
259
256
test ( 'useQuery hook respects refetchOnMountOrArgChange: true' , async ( ) => {
260
257
let data , isLoading , isFetching
261
258
function User ( ) {
262
- ; ( {
263
- data,
264
- isLoading,
265
- isFetching,
266
- } = api . endpoints . getIncrementedAmount . useQuery ( undefined , {
267
- refetchOnMountOrArgChange : true ,
268
- } ) )
259
+ ; ( { data, isLoading, isFetching } =
260
+ api . endpoints . getIncrementedAmount . useQuery ( undefined , {
261
+ refetchOnMountOrArgChange : true ,
262
+ } ) )
269
263
return (
270
264
< div >
271
265
< div data-testid = "isLoading" > { String ( isLoading ) } </ div >
@@ -308,13 +302,10 @@ describe('hooks tests', () => {
308
302
test ( 'useQuery does not refetch when refetchOnMountOrArgChange: NUMBER condition is not met' , async ( ) => {
309
303
let data , isLoading , isFetching
310
304
function User ( ) {
311
- ; ( {
312
- data,
313
- isLoading,
314
- isFetching,
315
- } = api . endpoints . getIncrementedAmount . useQuery ( undefined , {
316
- refetchOnMountOrArgChange : 10 ,
317
- } ) )
305
+ ; ( { data, isLoading, isFetching } =
306
+ api . endpoints . getIncrementedAmount . useQuery ( undefined , {
307
+ refetchOnMountOrArgChange : 10 ,
308
+ } ) )
318
309
return (
319
310
< div >
320
311
< div data-testid = "isLoading" > { String ( isLoading ) } </ div >
@@ -351,13 +342,10 @@ describe('hooks tests', () => {
351
342
test ( 'useQuery refetches when refetchOnMountOrArgChange: NUMBER condition is met' , async ( ) => {
352
343
let data , isLoading , isFetching
353
344
function User ( ) {
354
- ; ( {
355
- data,
356
- isLoading,
357
- isFetching,
358
- } = api . endpoints . getIncrementedAmount . useQuery ( undefined , {
359
- refetchOnMountOrArgChange : 0.5 ,
360
- } ) )
345
+ ; ( { data, isLoading, isFetching } =
346
+ api . endpoints . getIncrementedAmount . useQuery ( undefined , {
347
+ refetchOnMountOrArgChange : 0.5 ,
348
+ } ) )
361
349
return (
362
350
< div >
363
351
< div data-testid = "isLoading" > { String ( isLoading ) } </ div >
@@ -403,14 +391,11 @@ describe('hooks tests', () => {
403
391
let data , isLoading , isFetching
404
392
function User ( ) {
405
393
const [ skip , setSkip ] = React . useState ( true )
406
- ; ( {
407
- data,
408
- isLoading,
409
- isFetching,
410
- } = api . endpoints . getIncrementedAmount . useQuery ( undefined , {
411
- refetchOnMountOrArgChange : 0.5 ,
412
- skip,
413
- } ) )
394
+ ; ( { data, isLoading, isFetching } =
395
+ api . endpoints . getIncrementedAmount . useQuery ( undefined , {
396
+ refetchOnMountOrArgChange : 0.5 ,
397
+ skip,
398
+ } ) )
414
399
415
400
return (
416
401
< div >
@@ -452,14 +437,11 @@ describe('hooks tests', () => {
452
437
let data , isLoading , isFetching
453
438
function User ( ) {
454
439
const [ skip , setSkip ] = React . useState ( true )
455
- ; ( {
456
- data,
457
- isLoading,
458
- isFetching,
459
- } = api . endpoints . getIncrementedAmount . useQuery ( undefined , {
460
- skip,
461
- refetchOnMountOrArgChange : 0.5 ,
462
- } ) )
440
+ ; ( { data, isLoading, isFetching } =
441
+ api . endpoints . getIncrementedAmount . useQuery ( undefined , {
442
+ skip,
443
+ refetchOnMountOrArgChange : 0.5 ,
444
+ } ) )
463
445
464
446
return (
465
447
< div >
@@ -540,10 +522,8 @@ describe('hooks tests', () => {
540
522
let getRenderCount : ( ) => number = ( ) => 0
541
523
test ( 'useLazyQuery does not automatically fetch when mounted and has undefined data' , async ( ) => {
542
524
function User ( ) {
543
- const [
544
- fetchUser ,
545
- { data : hookData , isFetching, isUninitialized } ,
546
- ] = api . endpoints . getUser . useLazyQuery ( )
525
+ const [ fetchUser , { data : hookData , isFetching, isUninitialized } ] =
526
+ api . endpoints . getUser . useLazyQuery ( )
547
527
getRenderCount = useRenderCounter ( )
548
528
549
529
data = hookData
@@ -592,10 +572,8 @@ describe('hooks tests', () => {
592
572
let interval = 1000
593
573
function User ( ) {
594
574
const [ options , setOptions ] = React . useState < SubscriptionOptions > ( )
595
- const [
596
- fetchUser ,
597
- { data : hookData , isFetching, isUninitialized } ,
598
- ] = api . endpoints . getUser . useLazyQuery ( options )
575
+ const [ fetchUser , { data : hookData , isFetching, isUninitialized } ] =
576
+ api . endpoints . getUser . useLazyQuery ( options )
599
577
getRenderCount = useRenderCounter ( )
600
578
601
579
data = hookData
@@ -676,10 +654,8 @@ describe('hooks tests', () => {
676
654
677
655
test ( 'useLazyQuery accepts updated args and unsubscribes the original query' , async ( ) => {
678
656
function User ( ) {
679
- const [
680
- fetchUser ,
681
- { data : hookData , isFetching, isUninitialized } ,
682
- ] = api . endpoints . getUser . useLazyQuery ( )
657
+ const [ fetchUser , { data : hookData , isFetching, isUninitialized } ] =
658
+ api . endpoints . getUser . useLazyQuery ( )
683
659
684
660
data = hookData
685
661
@@ -766,10 +742,8 @@ describe('hooks tests', () => {
766
742
describe ( 'useMutation' , ( ) => {
767
743
test ( 'useMutation hook sets and unsets the isLoading flag when running' , async ( ) => {
768
744
function User ( ) {
769
- const [
770
- updateUser ,
771
- { isLoading } ,
772
- ] = api . endpoints . updateUser . useMutation ( )
745
+ const [ updateUser , { isLoading } ] =
746
+ api . endpoints . updateUser . useMutation ( )
773
747
774
748
return (
775
749
< div >
@@ -1217,10 +1191,8 @@ describe('hooks tests', () => {
1217
1191
let data , isLoading , isError
1218
1192
function User ( ) {
1219
1193
; ( { data, isError, isLoading } = api . endpoints . checkSession . useQuery ( ) )
1220
- const [
1221
- login ,
1222
- { isLoading : loginLoading } ,
1223
- ] = api . endpoints . login . useMutation ( )
1194
+ const [ login , { isLoading : loginLoading } ] =
1195
+ api . endpoints . login . useMutation ( )
1224
1196
1225
1197
return (
1226
1198
< div >
@@ -1310,10 +1282,8 @@ describe('hooks with createApi defaults set', () => {
1310
1282
let data , isLoading , isFetching
1311
1283
1312
1284
function User ( ) {
1313
- ; ( {
1314
- data,
1315
- isLoading,
1316
- } = defaultApi . endpoints . getIncrementedAmount . useQuery ( ) )
1285
+ ; ( { data, isLoading } =
1286
+ defaultApi . endpoints . getIncrementedAmount . useQuery ( ) )
1317
1287
return (
1318
1288
< div >
1319
1289
< div data-testid = "isLoading" > { String ( isLoading ) } </ div >
@@ -1338,12 +1308,10 @@ describe('hooks with createApi defaults set', () => {
1338
1308
unmount ( )
1339
1309
1340
1310
function OtherUser ( ) {
1341
- ; ( {
1342
- data,
1343
- isFetching,
1344
- } = defaultApi . endpoints . getIncrementedAmount . useQuery ( undefined , {
1345
- refetchOnMountOrArgChange : true ,
1346
- } ) )
1311
+ ; ( { data, isFetching } =
1312
+ defaultApi . endpoints . getIncrementedAmount . useQuery ( undefined , {
1313
+ refetchOnMountOrArgChange : true ,
1314
+ } ) )
1347
1315
return (
1348
1316
< div >
1349
1317
< div data-testid = "isFetching" > { String ( isFetching ) } </ div >
@@ -1370,10 +1338,8 @@ describe('hooks with createApi defaults set', () => {
1370
1338
let data , isLoading , isFetching
1371
1339
1372
1340
function User ( ) {
1373
- ; ( {
1374
- data,
1375
- isLoading,
1376
- } = defaultApi . endpoints . getIncrementedAmount . useQuery ( ) )
1341
+ ; ( { data, isLoading } =
1342
+ defaultApi . endpoints . getIncrementedAmount . useQuery ( ) )
1377
1343
return (
1378
1344
< div >
1379
1345
< div data-testid = "isLoading" > { String ( isLoading ) } </ div >
@@ -1398,12 +1364,10 @@ describe('hooks with createApi defaults set', () => {
1398
1364
unmount ( )
1399
1365
1400
1366
function OtherUser ( ) {
1401
- ; ( {
1402
- data,
1403
- isFetching,
1404
- } = defaultApi . endpoints . getIncrementedAmount . useQuery ( undefined , {
1405
- refetchOnMountOrArgChange : false ,
1406
- } ) )
1367
+ ; ( { data, isFetching } =
1368
+ defaultApi . endpoints . getIncrementedAmount . useQuery ( undefined , {
1369
+ refetchOnMountOrArgChange : false ,
1370
+ } ) )
1407
1371
return (
1408
1372
< div >
1409
1373
< div data-testid = "isFetching" > { String ( isFetching ) } </ div >
@@ -1965,6 +1929,19 @@ describe('hooks with createApi defaults set', () => {
1965
1929
expect ( getRenderCount ( ) ) . toBe ( 5 )
1966
1930
} )
1967
1931
1932
+ test ( 'useMutation return value contains originalArgs' , async ( ) => {
1933
+ const { result } = renderHook ( api . endpoints . increment . useMutation , {
1934
+ wrapper : storeRef . wrapper ,
1935
+ } )
1936
+
1937
+ const firstRenderResult = result . current
1938
+ expect ( firstRenderResult [ 1 ] . originalArgs ) . toBe ( undefined )
1939
+ firstRenderResult [ 0 ] ( 5 )
1940
+ const secondRenderResult = result . current
1941
+ expect ( firstRenderResult [ 1 ] . originalArgs ) . toBe ( undefined )
1942
+ expect ( secondRenderResult [ 1 ] . originalArgs ) . toBe ( 5 )
1943
+ } )
1944
+
1968
1945
it ( 'useMutation with selectFromResult option has a type error if the result is not an object' , async ( ) => {
1969
1946
function Counter ( ) {
1970
1947
const [ increment ] = api . endpoints . increment . useMutation ( {
0 commit comments