Loading...
Error: {{ error.message }}
Refreshing...
Loading...
Error: {{ error.message }}
Refreshing...
Something went wrong: {{ error.message }}
Hello, {{ data.name }}
Loading...
Saving...
Contact created!
``` Test it with a POST handler: ```ts import { http, HttpResponse } from 'msw' import { server } from './mocks/server' import CreateContact from './CreateContact.vue' it('creates a contact', async () => { server.use( http.post('/api/contacts', () => HttpResponse.json({ id: 3, name: 'Charlie' }), ), ) const wrapper = mountWithPlugins(CreateContact) await wrapper.find('input').setValue('Charlie') await wrapper.find('form').trigger('submit') await flushPromises() expect(wrapper.text()).toContain('Contact created!') }) ``` ## Tips * **`flushPromises()`**: Use `flushPromises()` from `@vue/test-utils` after actions that trigger async updates (initial query run, submit handlers, refetches). * **Inspecting cache state**: Use `useQueryCache()` inside tests to inspect or seed cache state. Since you're using a real `createPinia()`, the cache works exactly as it does in production. * **Simpler cases without MSW**: For narrow unit tests, pass a mocked query function directly: ```ts import { vi } from 'vitest' import { useQuery } from '@pinia/colada' const query = vi.fn().mockResolvedValue([{ id: 1, name: 'Alice' }]) const TestComponent = { setup() { const { data } = useQuery({ key: ['contacts'], query, }) return { data } }, template: `{{ data }}`,
}
const wrapper = mountWithPlugins(TestComponent)
await flushPromises()
expect(query).toHaveBeenCalledTimes(1)
expect(wrapper.text()).toContain('Alice')
```
However, MSW is preferred since it tests the full request pipeline.
---
---
url: /cookbook/tanstack-compat.md
---
# TanStack Query Compatibility Plugin
This plugin provides a compatibility layer for developers migrating from TanStack Query (Vue) to Pinia Colada, or for those who prefer the TanStack Query API style. It might not cover every single property or feature of TanStack Query, but it implements the most commonly used ones to make the transition smoother. If you find anything missing, please open a pull request to add it!
## Overview
The plugin adds TanStack Query Vue v5 compatible properties to both `useQuery` and `useMutation` composables via TypeScript module augmentation. This means you get full type safety and IntelliSense support.
## Installation
```bash
# or pnpm, or yarn, etc
npm i @pinia/colada-plugin-tanstack-compat
```
## Setup
Register the plugin when installing Pinia Colada:
```ts
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import { PiniaColada } from '@pinia/colada'
import { PiniaColadaTanStackCompat } from '@pinia/colada-plugin-tanstack-compat'
const app = createApp(App)
const pinia = createPinia()
app.use(pinia)
app.use(PiniaColada, {
plugins: [PiniaColadaTanStackCompat()],
})
```
## Features
### useQuery Extensions
The plugin adds 12 properties to every query:
| Property | Type | Description | TanStack Equivalent |
| --------------------- | ----------------------------------- | -------------------------------------------------- | --------------------- |
| `isSuccess` | `ComputedRefLast updated: {{ lastUpdated }}