You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> If your applications actual TanStack Query config is used in unit tests, make sure `withDevtools` is not accidentally included in test providers. This can cause slow tests. It is best to keep test and production configs separate.
33
33
34
-
If you share helpers, remember to call `queryClient.clear()` (or build a new instance) in `afterEach` so data from one test never bleeds into another.
34
+
If you share helpers, remember to call `queryClient.clear()` (or build a new instance) in `afterEach` so data from one test never bleeds into another. We generally prefer creating a fresh `QueryClient` per test: clearing only removes cached data, not custom defaults or listeners, so a reused client can leak configuration changes between specs and make failures harder to reason about. A new client keeps setup explicit and avoids any “invisible globals” influencing results.
35
35
36
36
## First query test
37
37
@@ -63,6 +63,14 @@ await Promise.resolve()
63
63
awaitappRef.whenStable()
64
64
```
65
65
66
+
In the Angular Query repo we wrap this pattern in a `flushQueryUpdates()` helper (see `packages/angular-query-experimental/src/__tests__/test-utils.ts`) so every spec documents why the extra tick is required:
67
+
68
+
```ts
69
+
TestBed.tick()
70
+
awaitflushQueryUpdates()
71
+
awaitappRef.whenStable()
72
+
```
73
+
66
74
## Testing components
67
75
68
76
For components, bootstrap them through `TestBed.createComponent`, then await `fixture.whenStable()`:
0 commit comments