Skip to content

Commit 9320646

Browse files
committed
test(loaders): fix test
1 parent f86907e commit 9320646

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
}
189189
},
190190
"devDependencies": {
191-
"@pinia/colada": "^0.8.2",
191+
"@pinia/colada": "^0.9.0",
192192
"@shikijs/vitepress-twoslash": "1.16.3",
193193
"@tanstack/vue-query": "^5.55.4",
194194
"@types/node": "^20.16.1",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/data-loaders/defineColadaLoader.spec.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @vitest-environment happy-dom
33
*/
4-
import { App, defineComponent, markRaw } from 'vue'
4+
import { App, defineComponent, markRaw, nextTick } from 'vue'
55
import { defineColadaLoader } from './defineColadaLoader'
66
import {
77
describe,
@@ -25,7 +25,6 @@ import { enableAutoUnmount, mount } from '@vue/test-utils'
2525
import RouterViewMock from '../../tests/data-loaders/RouterViewMock.vue'
2626
import { setActivePinia, createPinia, getActivePinia } from 'pinia'
2727
import {
28-
useQuery,
2928
PiniaColada,
3029
useQueryCache,
3130
reviveTreeMap,
@@ -68,7 +67,13 @@ describe(
6867
function singleLoaderOneRoute<Loader extends UseDataLoader>(
6968
useData: Loader,
7069
pluginOptions?: Omit<DataLoaderPluginOptions, 'router'>
71-
) {
70+
): {
71+
wrapper: ReturnType<typeof mount>
72+
router: ReturnType<typeof getRouter>
73+
// technically it should be () => ReturnType<Loader> but it doesn't infer all the types
74+
useData: Loader,
75+
app: App
76+
} {
7277
let useDataResult: ReturnType<Loader>
7378
const component = defineComponent({
7479
setup() {
@@ -111,6 +116,7 @@ describe(
111116
return {
112117
wrapper,
113118
router,
119+
// @ts-expect-error: not exactly Loader
114120
useData: () => {
115121
if (useDataResult) {
116122
return useDataResult
@@ -148,7 +154,7 @@ describe(
148154
})
149155

150156
it('updates data loader data if internal data changes', async () => {
151-
const query = vi.fn().mockResolvedValue('data')
157+
const query = vi.fn(async () => 'data')
152158

153159
const { router, useData } = singleLoaderOneRoute(
154160
defineColadaLoader({
@@ -165,24 +171,19 @@ describe(
165171
const wrapper = mount(
166172
defineComponent({
167173
setup() {
168-
return useQuery({
169-
query,
170-
key: ['id'],
171-
})
174+
const caches = useQueryCache()
175+
return { caches }
172176
},
173-
template: `<div>{{ data }}</div>`,
177+
template: `<div></div>`,
174178
}),
175179
{
176180
global: {
177181
plugins: [getActivePinia()!, PiniaColada],
178182
},
179183
}
180184
)
181-
query.mockResolvedValue('new')
182-
await wrapper.vm.refetch()
183-
await vi.runAllTimersAsync()
184-
expect(query).toHaveBeenCalledTimes(2)
185-
expect(wrapper.vm.data).toBe('new')
185+
wrapper.vm.caches.setQueryData(['id'], 'new')
186+
await nextTick()
186187
expect(loaderData.value).toBe('new')
187188
})
188189

0 commit comments

Comments
 (0)