From d4513d951a31d152ba935bb8872165b7e01728ad Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Tue, 20 Oct 2026 17:23:24 +0900 Subject: [PATCH] docs(svelte/testing): add the imports to the 'withEffectRoot' and fake timers examples so each can be used as its own file --- docs/framework/svelte/testing.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/framework/svelte/testing.md b/docs/framework/svelte/testing.md index 015269fdc1..ab05997168 100644 --- a/docs/framework/svelte/testing.md +++ b/docs/framework/svelte/testing.md @@ -90,6 +90,10 @@ it('should fetch the greeting', async () => { To avoid repeating `$effect.root` and its cleanup in every test, you can also wrap the whole test body with a helper that runs it inside an effect root: ```ts +import { expect, it, vi } from 'vitest' +import { QueryClient, createQuery } from '@tanstack/svelte-query' +import { greetingOptions } from './queries' + function withEffectRoot(fn: () => Promise) { return async () => { let promise!: Promise @@ -192,6 +196,11 @@ it('should render the greeting', async () => { `vi.waitFor` and `findByText` retry until the assertion passes, which works for query functions that wait on real requests. When the query function waits on a timer, you can use fake timers and advance them instead, for example with [`vi.advanceTimersByTimeAsync`](https://vitest.dev/api/vi.html#vi-advancetimersbytimeasync). Restore real timers in `afterEach`, so they are restored even when an assertion fails: ```ts +import { render } from '@testing-library/svelte' +import { afterEach, beforeEach, expect, it, vi } from 'vitest' +import { QueryClient } from '@tanstack/svelte-query' +import GreetingTest from './GreetingTest.svelte' + beforeEach(() => { vi.useFakeTimers() })