Skip to content

Commit

Permalink
test(vue-query): add test and improve typing (#8103)
Browse files Browse the repository at this point in the history
* test(vue-query): add test for clone getters returning values in queryKey

* fix(vue-query): improve typing in vueQueryPlugin.test.ts to resolve errors on tsc

---------

Co-authored-by: Dominik Dorfmeister <[email protected]>
  • Loading branch information
kickbelldev and TkDodo authored Oct 1, 2024
1 parent 71c5f88 commit 69476f0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 6 additions & 0 deletions packages/vue-query/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ describe('utils', () => {
})
})

test('should clone getters returning values in queryKey', () => {
const val = ref({ queryKey: [1, 2, () => '3'] })
const cp = cloneDeepUnref(val)
expect(cp).toStrictEqual({ queryKey: [1, 2, '3'] })
})

test('should unref undefined', () => {
expect(cloneDeepUnref(ref(undefined))).toBe(undefined)
})
Expand Down
10 changes: 6 additions & 4 deletions packages/vue-query/src/__tests__/vueQueryPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ vi.mock('../devtools/devtools')
vi.mock('../useQueryClient')
vi.mock('../useBaseQuery')

type UnmountCallback = () => void

interface TestApp extends App {
onUnmount: Function
_unmount: Function
onUnmount: UnmountCallback
_unmount: UnmountCallback
_mixin: ComponentOptions
_provided: Record<string, any>
$root: TestApp
Expand All @@ -29,11 +31,11 @@ function getAppMock(withUnmountHook = false): TestApp {
provide: vi.fn(),
unmount: vi.fn(),
onUnmount: withUnmountHook
? vi.fn((u: Function) => {
? vi.fn((u: UnmountCallback) => {
mock._unmount = u
})
: undefined,
mixin: (m: ComponentOptions): any => {
mixin: (m: ComponentOptions) => {
mock._mixin = m
},
} as unknown as TestApp
Expand Down

0 comments on commit 69476f0

Please sign in to comment.