Open History to see the last commit
1import { describe, expect, test } from 'vitest'
2import { render, waitFor } from '@testing-library/svelte'
3import { QueryClient } from '@tanstack/query-core'
4import { sleep } from '@tanstack/query-test-utils'
5import BaseExample from './BaseExample.svelte'
6import CombineExample from './CombineExample.svelte'
7β
8describe('createQueries', () => {
9 test('Render and wait for success', async () => {
10 const rendered = render(BaseExample, {
11 props: {
12 options: {
13 queries: [
14 {
15 queryKey: ['key-1'],
16 queryFn: async () => {
17 await sleep(5)
18 return 'Success 1'
19 },
20 },
21 {
22 queryKey: ['key-2'],
23 queryFn: async () => {
24 await sleep(5)
25 return 'Success 2'
26 },
27 },
28 ],
29 },
30 queryClient: new QueryClient(),
31 },
32 })
33β
34 await waitFor(() => {
35 expect(rendered.getByText('Status 1: pending')).toBeInTheDocument()
36 expect(rendered.getByText('Status 2: pending')).toBeInTheDocument()
37 })
38β
39 await waitFor(() => {
40 expect(rendered.getByText('Status 1: success')).toBeInTheDocument()
41 expect(rendered.getByText('Status 2: success')).toBeInTheDocument()
42 })
43 })
44β
45 test('Combine queries', async () => {
46 const rendered = render(CombineExample, {
47 props: {
48 queryClient: new QueryClient(),
49 },
50 })
51β
52 await waitFor(() => {
53 expect(rendered.getByText('isPending: true')).toBeInTheDocument()
54 })
55β
56 await waitFor(() => {
57 expect(rendered.getByText('Data: 1,2,3')).toBeInTheDocument()
58 })
59 })
60})