Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

Reset.svelte

23 lines672 Bytes

1<script lang="ts">
2 import { sleep } from '@tanstack/query-test-utils'
3 import { createMutation, setQueryClientContext } from '../../src/index.js'
4 import type { QueryClient } from '@tanstack/query-core'
5​
6 type Props = {
7 queryClient: QueryClient
8 }
9​
10 let { queryClient }: Props = $props()
11​
12 setQueryClientContext(queryClient)
13​
14 const mutation = createMutation(() => ({
15 mutationFn: () =>
16 sleep(10).then(() => Promise.reject(new Error('Expected mock error'))),
17 }))
18</script>
19​
20<button onclick={() => mutation.reset()}>Reset</button>
21<button onclick={() => mutation.mutate()}>Mutate</button>
22​
23<div>Error: {mutation.error?.message ?? 'undefined'}</div>