Skip to content

Commit c597f76

Browse files
sukvvonmanudeli
andauthored
test(svelte-query/useIsMutating): switch to fake timers, add 'expect', 'vi.waitFor', and replace 'findByText' with 'getByText' (#9387)
Co-authored-by: Jonghyeon Ko <[email protected]>
1 parent bce4d7e commit c597f76

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed
Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
1-
import { describe, test } from 'vitest'
1+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
22
import { fireEvent, render } from '@testing-library/svelte'
33
import BaseExample from './BaseExample.svelte'
44

55
describe('useIsFetching', () => {
6+
beforeEach(() => {
7+
vi.useFakeTimers()
8+
})
9+
10+
afterEach(() => {
11+
vi.useRealTimers()
12+
})
13+
614
test('should update as queries start and stop fetching', async () => {
715
const rendered = render(BaseExample)
816

9-
await rendered.findByText('isMutating: 0')
17+
await vi.waitFor(() =>
18+
expect(rendered.getByText('isMutating: 0')).toBeInTheDocument(),
19+
)
1020
fireEvent.click(rendered.getByRole('button', { name: /Trigger/i }))
11-
await rendered.findByText('isMutating: 1')
12-
await rendered.findByText('isMutating: 0')
21+
await vi.waitFor(() =>
22+
expect(rendered.getByText('isMutating: 1')).toBeInTheDocument(),
23+
)
24+
await vi.waitFor(() =>
25+
expect(rendered.getByText('isMutating: 0')).toBeInTheDocument(),
26+
)
1327
})
1428
})

0 commit comments

Comments
 (0)