1
- import { describe , expect , it } from 'vitest'
1
+ import { describe , expect , it , vi } from 'vitest'
2
2
import {
3
3
addToEnd ,
4
4
addToStart ,
5
5
hashKey ,
6
+ hashQueryKeyByOptions ,
6
7
isPlainArray ,
7
8
isPlainObject ,
8
9
keepPreviousData ,
@@ -15,6 +16,28 @@ import { Mutation } from '../mutation'
15
16
import { createQueryClient } from './utils'
16
17
17
18
describe ( '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
+
18
41
describe ( 'shallowEqualObjects' , ( ) => {
19
42
it ( 'should return `true` for shallow equal objects' , ( ) => {
20
43
expect ( shallowEqualObjects ( { a : 1 } , { a : 1 } ) ) . toEqual ( true )
0 commit comments