|
1 | 1 | import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' |
2 | | -import { fireEvent, render } from '@solidjs/testing-library' |
| 2 | +import { fireEvent } from '@solidjs/testing-library' |
3 | 3 | import { createEffect, createRenderEffect } from 'solid-js' |
4 | 4 | import { queryKey, sleep } from '@tanstack/query-test-utils' |
5 | | -import { |
6 | | - QueryClient, |
7 | | - QueryClientProvider, |
8 | | - useIsMutating, |
9 | | - useMutation, |
10 | | - useMutationState, |
11 | | -} from '..' |
| 5 | +import { QueryClient, useIsMutating, useMutation, useMutationState } from '..' |
12 | 6 | import { mutationOptions } from '../mutationOptions' |
| 7 | +import { renderWithClient } from './utils' |
13 | 8 | import type { MutationState } from '@tanstack/query-core' |
14 | 9 |
|
15 | 10 | describe('mutationOptions', () => { |
@@ -65,11 +60,7 @@ describe('mutationOptions', () => { |
65 | 60 | ) |
66 | 61 | } |
67 | 62 |
|
68 | | - const rendered = render(() => ( |
69 | | - <QueryClientProvider client={queryClient}> |
70 | | - <Mutation /> |
71 | | - </QueryClientProvider> |
72 | | - )) |
| 63 | + const rendered = renderWithClient(queryClient, () => <Mutation />) |
73 | 64 |
|
74 | 65 | fireEvent.click(rendered.getByRole('button', { name: /mutate/i })) |
75 | 66 | expect(isMutatingArray[0]).toEqual(0) |
@@ -101,11 +92,7 @@ describe('mutationOptions', () => { |
101 | 92 | ) |
102 | 93 | } |
103 | 94 |
|
104 | | - const rendered = render(() => ( |
105 | | - <QueryClientProvider client={queryClient}> |
106 | | - <Mutation /> |
107 | | - </QueryClientProvider> |
108 | | - )) |
| 95 | + const rendered = renderWithClient(queryClient, () => <Mutation />) |
109 | 96 |
|
110 | 97 | fireEvent.click(rendered.getByRole('button', { name: /mutate/i })) |
111 | 98 | expect(isMutatingArray[0]).toEqual(0) |
@@ -144,11 +131,7 @@ describe('mutationOptions', () => { |
144 | 131 | ) |
145 | 132 | } |
146 | 133 |
|
147 | | - const rendered = render(() => ( |
148 | | - <QueryClientProvider client={queryClient}> |
149 | | - <Mutation /> |
150 | | - </QueryClientProvider> |
151 | | - )) |
| 134 | + const rendered = renderWithClient(queryClient, () => <Mutation />) |
152 | 135 |
|
153 | 136 | fireEvent.click(rendered.getByRole('button', { name: /mutate1/i })) |
154 | 137 | fireEvent.click(rendered.getByRole('button', { name: /mutate2/i })) |
@@ -189,11 +172,7 @@ describe('mutationOptions', () => { |
189 | 172 | ) |
190 | 173 | } |
191 | 174 |
|
192 | | - const rendered = render(() => ( |
193 | | - <QueryClientProvider client={queryClient}> |
194 | | - <Mutation /> |
195 | | - </QueryClientProvider> |
196 | | - )) |
| 175 | + const rendered = renderWithClient(queryClient, () => <Mutation />) |
197 | 176 |
|
198 | 177 | fireEvent.click(rendered.getByRole('button', { name: /mutate1/i })) |
199 | 178 | fireEvent.click(rendered.getByRole('button', { name: /mutate2/i })) |
@@ -223,11 +202,7 @@ describe('mutationOptions', () => { |
223 | 202 | ) |
224 | 203 | } |
225 | 204 |
|
226 | | - const rendered = render(() => ( |
227 | | - <QueryClientProvider client={queryClient}> |
228 | | - <Mutation /> |
229 | | - </QueryClientProvider> |
230 | | - )) |
| 205 | + const rendered = renderWithClient(queryClient, () => <Mutation />) |
231 | 206 |
|
232 | 207 | const mutationCache = queryClient.getMutationCache() |
233 | 208 | const unsubscribe = mutationCache.subscribe(() => { |
@@ -263,11 +238,7 @@ describe('mutationOptions', () => { |
263 | 238 | ) |
264 | 239 | } |
265 | 240 |
|
266 | | - const rendered = render(() => ( |
267 | | - <QueryClientProvider client={queryClient}> |
268 | | - <Mutation /> |
269 | | - </QueryClientProvider> |
270 | | - )) |
| 241 | + const rendered = renderWithClient(queryClient, () => <Mutation />) |
271 | 242 |
|
272 | 243 | const mutationCache = queryClient.getMutationCache() |
273 | 244 | const unsubscribe = mutationCache.subscribe(() => { |
@@ -310,11 +281,7 @@ describe('mutationOptions', () => { |
310 | 281 | ) |
311 | 282 | } |
312 | 283 |
|
313 | | - const rendered = render(() => ( |
314 | | - <QueryClientProvider client={queryClient}> |
315 | | - <Mutation /> |
316 | | - </QueryClientProvider> |
317 | | - )) |
| 284 | + const rendered = renderWithClient(queryClient, () => <Mutation />) |
318 | 285 |
|
319 | 286 | const mutationCache = queryClient.getMutationCache() |
320 | 287 | const unsubscribe = mutationCache.subscribe(() => { |
@@ -358,11 +325,7 @@ describe('mutationOptions', () => { |
358 | 325 | ) |
359 | 326 | } |
360 | 327 |
|
361 | | - const rendered = render(() => ( |
362 | | - <QueryClientProvider client={queryClient}> |
363 | | - <Mutation /> |
364 | | - </QueryClientProvider> |
365 | | - )) |
| 328 | + const rendered = renderWithClient(queryClient, () => <Mutation />) |
366 | 329 |
|
367 | 330 | const mutationCache = queryClient.getMutationCache() |
368 | 331 | const unsubscribe = mutationCache.subscribe(() => { |
@@ -416,11 +379,7 @@ describe('mutationOptions', () => { |
416 | 379 | ) |
417 | 380 | } |
418 | 381 |
|
419 | | - const rendered = render(() => ( |
420 | | - <QueryClientProvider client={queryClient}> |
421 | | - <Mutation /> |
422 | | - </QueryClientProvider> |
423 | | - )) |
| 382 | + const rendered = renderWithClient(queryClient, () => <Mutation />) |
424 | 383 |
|
425 | 384 | expect(mutationStateArray[0]).toEqual([]) |
426 | 385 |
|
@@ -454,11 +413,7 @@ describe('mutationOptions', () => { |
454 | 413 | ) |
455 | 414 | } |
456 | 415 |
|
457 | | - const rendered = render(() => ( |
458 | | - <QueryClientProvider client={queryClient}> |
459 | | - <Mutation /> |
460 | | - </QueryClientProvider> |
461 | | - )) |
| 416 | + const rendered = renderWithClient(queryClient, () => <Mutation />) |
462 | 417 |
|
463 | 418 | expect(mutationStateArray[0]).toEqual([]) |
464 | 419 |
|
@@ -499,11 +454,7 @@ describe('mutationOptions', () => { |
499 | 454 | ) |
500 | 455 | } |
501 | 456 |
|
502 | | - const rendered = render(() => ( |
503 | | - <QueryClientProvider client={queryClient}> |
504 | | - <Mutation /> |
505 | | - </QueryClientProvider> |
506 | | - )) |
| 457 | + const rendered = renderWithClient(queryClient, () => <Mutation />) |
507 | 458 |
|
508 | 459 | expect(mutationStateArray[0]).toEqual([]) |
509 | 460 |
|
@@ -546,11 +497,7 @@ describe('mutationOptions', () => { |
546 | 497 | ) |
547 | 498 | } |
548 | 499 |
|
549 | | - const rendered = render(() => ( |
550 | | - <QueryClientProvider client={queryClient}> |
551 | | - <Mutation /> |
552 | | - </QueryClientProvider> |
553 | | - )) |
| 500 | + const rendered = renderWithClient(queryClient, () => <Mutation />) |
554 | 501 |
|
555 | 502 | expect(mutationStateArray[0]).toEqual([]) |
556 | 503 |
|
|
0 commit comments