1- import { describe , expect , it } from 'vitest'
1+ import { describe , expect , it , vi } from 'vitest'
22import {
33 addToEnd ,
44 addToStart ,
55 hashKey ,
6+ hashQueryKeyByOptions ,
67 isPlainArray ,
78 isPlainObject ,
89 keepPreviousData ,
@@ -15,6 +16,28 @@ import { Mutation } from '../mutation'
1516import { createQueryClient } from './utils'
1617
1718describe ( 'core/utils' , ( ) => {
19+ describe ( 'hashQueryKeyByOptions' , ( ) => {
20+ it ( 'should use custom hash function when provided in options' , ( ) => {
21+ const queryKey = [ 'test' , { a : 1 , b : 2 } ]
22+ const customHashFn = vi . fn ( ( ) => 'custom-hash' )
23+
24+ const result = hashQueryKeyByOptions ( queryKey , {
25+ queryKeyHashFn : customHashFn ,
26+ } )
27+
28+ expect ( customHashFn ) . toHaveBeenCalledWith ( queryKey )
29+ expect ( result ) . toEqual ( 'custom-hash' )
30+ } )
31+
32+ it ( 'should use default hash function when no options provided' , ( ) => {
33+ const queryKey = [ 'test' , { a : 1 , b : 2 } ]
34+ const defaultResult = hashKey ( queryKey )
35+ const result = hashQueryKeyByOptions ( queryKey )
36+
37+ expect ( result ) . toEqual ( defaultResult )
38+ } )
39+ } )
40+
1841 describe ( 'shallowEqualObjects' , ( ) => {
1942 it ( 'should return `true` for shallow equal objects' , ( ) => {
2043 expect ( shallowEqualObjects ( { a : 1 } , { a : 1 } ) ) . toEqual ( true )
0 commit comments