@@ -11,7 +11,7 @@ interface TestItem {
1111 value ?: number
1212}
1313
14- const getId = ( item : TestItem ) => item . id
14+ const getKey = ( item : TestItem ) => item . id
1515
1616// Helper to advance timers and allow microtasks to flush
1717const flushPromises = ( ) => new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) )
@@ -51,7 +51,7 @@ describe(`QueryCollection`, () => {
5151 queryClient,
5252 queryKey,
5353 queryFn,
54- getId ,
54+ getKey ,
5555 }
5656
5757 const { options } = queryCollectionOptions ( config )
@@ -111,7 +111,7 @@ describe(`QueryCollection`, () => {
111111 queryClient,
112112 queryKey,
113113 queryFn,
114- getId ,
114+ getKey ,
115115 }
116116
117117 const { options, refetch } = queryCollectionOptions ( config )
@@ -192,7 +192,7 @@ describe(`QueryCollection`, () => {
192192 queryClient,
193193 queryKey,
194194 queryFn,
195- getId ,
195+ getKey ,
196196 retry : 0 , // Disable retries for this test case
197197 } )
198198 const collection = new Collection ( options )
@@ -242,7 +242,7 @@ describe(`QueryCollection`, () => {
242242 queryClient,
243243 queryKey,
244244 queryFn,
245- getId ,
245+ getKey ,
246246 } )
247247 const collection = new Collection ( options )
248248
@@ -290,7 +290,7 @@ describe(`QueryCollection`, () => {
290290 queryClient,
291291 queryKey,
292292 queryFn,
293- getId ,
293+ getKey ,
294294 } )
295295 const collection = new Collection ( options )
296296
@@ -353,7 +353,7 @@ describe(`QueryCollection`, () => {
353353 consoleSpy . mockRestore ( )
354354 } )
355355
356- it ( `should use the provided getId function to identify items` , async ( ) => {
356+ it ( `should use the provided getKey function to identify items` , async ( ) => {
357357 const queryKey = [ `customKeyTest` ]
358358
359359 // Items with a non-standard ID field
@@ -364,15 +364,15 @@ describe(`QueryCollection`, () => {
364364
365365 const queryFn = vi . fn ( ) . mockResolvedValue ( items )
366366
367- // Create a spy for the getId function
368- const getIdSpy = vi . fn ( ( item : any ) => item . customId )
367+ // Create a spy for the getKey function
368+ const getKeySpy = vi . fn ( ( item : any ) => item . customId )
369369
370370 const { options, refetch } = queryCollectionOptions ( {
371371 id : `test` ,
372372 queryClient,
373373 queryKey,
374374 queryFn,
375- getId : getIdSpy ,
375+ getKey : getKeySpy ,
376376 } )
377377 const collection = new Collection ( options )
378378
@@ -382,10 +382,10 @@ describe(`QueryCollection`, () => {
382382 expect ( collection . state . size ) . toBe ( items . length )
383383 } )
384384
385- // Verify getId was called for each item
386- expect ( getIdSpy ) . toHaveBeenCalledTimes ( items . length * 2 )
385+ // Verify getKey was called for each item
386+ expect ( getKeySpy ) . toHaveBeenCalledTimes ( items . length * 2 )
387387 items . forEach ( ( item ) => {
388- expect ( getIdSpy ) . toHaveBeenCalledWith ( item )
388+ expect ( getKeySpy ) . toHaveBeenCalledWith ( item )
389389 } )
390390
391391 // Verify items are stored with the custom keys
@@ -406,7 +406,7 @@ describe(`QueryCollection`, () => {
406406 ]
407407
408408 // Reset the spy to track new calls
409- getIdSpy . mockClear ( )
409+ getKeySpy . mockClear ( )
410410 queryFn . mockResolvedValueOnce ( updatedItems )
411411
412412 // Trigger a refetch
@@ -415,11 +415,11 @@ describe(`QueryCollection`, () => {
415415 expect ( queryFn ) . toHaveBeenCalledTimes ( 2 )
416416 expect ( collection . state . size ) . toBe ( updatedItems . length )
417417
418- // Verify getId was called at least once for each item
418+ // Verify getKey was called at least once for each item
419419 // It may be called multiple times per item during the diffing process
420- expect ( getIdSpy ) . toHaveBeenCalled ( )
420+ expect ( getKeySpy ) . toHaveBeenCalled ( )
421421 updatedItems . forEach ( ( item ) => {
422- expect ( getIdSpy ) . toHaveBeenCalledWith ( item )
422+ expect ( getKeySpy ) . toHaveBeenCalledWith ( item )
423423 } )
424424
425425 // Verify the state reflects the changes
@@ -450,7 +450,7 @@ describe(`QueryCollection`, () => {
450450 queryClient,
451451 queryKey,
452452 queryFn,
453- getId ,
453+ getKey ,
454454 onInsert,
455455 onUpdate,
456456 onDelete,
@@ -483,7 +483,7 @@ describe(`QueryCollection`, () => {
483483 queryClient,
484484 queryKey,
485485 queryFn,
486- getId ,
486+ getKey ,
487487 onInsert,
488488 onUpdate,
489489 onDelete,
@@ -520,7 +520,7 @@ describe(`QueryCollection`, () => {
520520 queryClient,
521521 queryKey : [ `refetchTest` , `default` ] ,
522522 queryFn : vi . fn ( ) . mockResolvedValue ( [ { id : `1` , name : `Item 1` } ] ) ,
523- getId ,
523+ getKey ,
524524 onInsert : onInsertDefault ,
525525 }
526526
@@ -529,7 +529,7 @@ describe(`QueryCollection`, () => {
529529 queryClient,
530530 queryKey : [ `refetchTest` , `false` ] ,
531531 queryFn : vi . fn ( ) . mockResolvedValue ( [ { id : `1` , name : `Item 1` } ] ) ,
532- getId ,
532+ getKey ,
533533 onInsert : onInsertFalse ,
534534 }
535535
0 commit comments