Skip to content

Commit 37c0774

Browse files
dngur9801TkDodo
authored andcommitted
test(query-core): add hashQueryKeyByOptions test code (#8736)
* test: add hashQueryKeyByOptions test code * fix: test code * fix: eslint --------- Co-authored-by: Dominik Dorfmeister <[email protected]>
1 parent 4ac99cc commit 37c0774

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

packages/query-core/src/__tests__/utils.test.tsx

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { describe, expect, it } from 'vitest'
1+
import { describe, expect, it, vi } from 'vitest'
22
import {
33
addToEnd,
44
addToStart,
55
hashKey,
6+
hashQueryKeyByOptions,
67
isPlainArray,
78
isPlainObject,
89
keepPreviousData,
@@ -15,6 +16,28 @@ import { Mutation } from '../mutation'
1516
import { createQueryClient } from './utils'
1617

1718
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+
1841
describe('shallowEqualObjects', () => {
1942
it('should return `true` for shallow equal objects', () => {
2043
expect(shallowEqualObjects({ a: 1 }, { a: 1 })).toEqual(true)

0 commit comments

Comments
 (0)