Unit testing #143
Unanswered
BhaskaranR
asked this question in
Q&A
Replies: 2 comments 1 reply
-
Hi, there is no guide currently regarding testing. If you are thinking about testing import { VueQueryPlugin, VueQueryPluginOptions } from 'vue-query';
const vueQueryOptions: VueQueryPluginOptions = {
queryClientConfig: {
defaultOptions: {
queries: {
retry: false,
cacheTime: Infinity
}
}
}
}
app.use(VueQueryPlugin, vueQueryOptions); Other than that, just mock your API calls and you should be good to go. |
Beta Was this translation helpful? Give feedback.
0 replies
-
If you want to test using vitest I think you can do something like this npm install vue-query && npm install vue-test-composables vitest p-wait-for -D import { useQuery, useQueryProvider } from 'vue-query'
import { renderComposable } from 'vue-test-composables'
import { test, expect } from 'vitest'
import waitFor from 'p-wait-for'
function useTodo() {
return useQuery('todo', () =>
fetch('https://jsonplaceholder.typicode.com/todos/1').then(
(res) => res.json
)
)
}
test('useTodo', async () => {
const { result } = renderComposable(() => useTodo(), {
provider() {
useQueryProvider({
defaultOptions: {
queries: {
retry: false,
cacheTime: Infinity,
},
},
})
},
})
await waitFor(() => result.isSuccess.value)
await expect(result.data.value).resolves.toMatchObject({
userId: 1,
id: 1,
title: 'delectus aut autem',
completed: false,
})
}) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
do we have any examples with vitest or jest?
Beta Was this translation helpful? Give feedback.
All reactions