@tanstack/solid-query 5.0.0-alpha.4 → 5.0.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,7 @@ import { queryKey } from './utils';
3
3
  import { QueryCache } from '@tanstack/query-core';
4
4
  import { createQuery, QueryClientProvider, useQueryClient } from '..';
5
5
  import { createQueryClient, sleep } from './utils';
6
+ import { vi } from 'vitest';
6
7
  describe('QueryClientProvider', () => {
7
8
  it('sets a specific cache for all queries to use', async () => {
8
9
  const key = queryKey();
@@ -106,7 +107,7 @@ describe('QueryClientProvider', () => {
106
107
  });
107
108
  describe('useQueryClient', () => {
108
109
  it('should throw an error if no query client has been set', () => {
109
- const consoleMock = jest
110
+ const consoleMock = vi
110
111
  .spyOn(console, 'error')
111
112
  .mockImplementation(() => undefined);
112
113
  function Page() {
@@ -3,6 +3,7 @@ import { createQueryClient, sleep } from './utils';
3
3
  import { createEffect, createRenderEffect, createSignal, For, Index, Match, Switch, } from 'solid-js';
4
4
  import { createInfiniteQuery, QueryCache, QueryClientProvider, keepPreviousData, } from '..';
5
5
  import { Blink, queryKey, setActTimeout } from './utils';
6
+ import { vi } from 'vitest';
6
7
  const pageSize = 10;
7
8
  const fetchItems = async (page, ts, noNext, noPrev) => {
8
9
  await sleep(10);
@@ -582,9 +583,9 @@ describe('useInfiniteQuery', () => {
582
583
  const start = 10;
583
584
  const onAborts = [];
584
585
  const abortListeners = [];
585
- const fetchPage = jest.fn(async ({ pageParam, signal }) => {
586
- const onAbort = jest.fn();
587
- const abortListener = jest.fn();
586
+ const fetchPage = vi.fn(async ({ pageParam, signal }) => {
587
+ const onAbort = vi.fn();
588
+ const abortListener = vi.fn();
588
589
  onAborts.push(onAbort);
589
590
  abortListeners.push(abortListener);
590
591
  signal.onabort = onAbort;
@@ -648,9 +649,9 @@ describe('useInfiniteQuery', () => {
648
649
  const start = 10;
649
650
  const onAborts = [];
650
651
  const abortListeners = [];
651
- const fetchPage = jest.fn(async ({ pageParam, signal }) => {
652
- const onAbort = jest.fn();
653
- const abortListener = jest.fn();
652
+ const fetchPage = vi.fn(async ({ pageParam, signal }) => {
653
+ const onAbort = vi.fn();
654
+ const abortListener = vi.fn();
654
655
  onAborts.push(onAbort);
655
656
  abortListeners.push(abortListener);
656
657
  signal.onabort = onAbort;
@@ -1131,7 +1132,7 @@ describe('useInfiniteQuery', () => {
1131
1132
  </>}>
1132
1133
  <Match when={state.status === 'pending'}>Loading...</Match>
1133
1134
  <Match when={state.status === 'error'}>
1134
- <span>Error: {state.error.message}</span>
1135
+ <span>Error: {state.error?.message}</span>
1135
1136
  </Match>
1136
1137
  </Switch>
1137
1138
  </div>);
@@ -1221,7 +1222,7 @@ describe('useInfiniteQuery', () => {
1221
1222
  </>}>
1222
1223
  <Match when={state.status === 'pending'}>Loading...</Match>
1223
1224
  <Match when={state.status === 'error'}>
1224
- <span>Error: {state.error.message}</span>
1225
+ <span>Error: {state.error?.message}</span>
1225
1226
  </Match>
1226
1227
  </Switch>
1227
1228
  </div>);
@@ -1264,10 +1265,10 @@ describe('useInfiniteQuery', () => {
1264
1265
  });
1265
1266
  it('should cancel the query function when there are no more subscriptions', async () => {
1266
1267
  const key = queryKey();
1267
- let cancelFn = jest.fn();
1268
+ let cancelFn = vi.fn();
1268
1269
  const queryFn = ({ signal }) => {
1269
1270
  const promise = new Promise((resolve, reject) => {
1270
- cancelFn = jest.fn(() => reject('Cancelled'));
1271
+ cancelFn = vi.fn(() => reject('Cancelled'));
1271
1272
  signal?.addEventListener('abort', cancelFn);
1272
1273
  sleep(20).then(() => resolve('OK'));
1273
1274
  });
@@ -3,6 +3,7 @@ import { createEffect, createRenderEffect, createSignal, ErrorBoundary, } from '
3
3
  import { fireEvent, render, screen, waitFor } from 'solid-testing-library';
4
4
  import { createMutation, MutationCache, QueryCache, QueryClientProvider, } from '..';
5
5
  import { createQueryClient, mockNavigatorOnLine, queryKey, setActTimeout, sleep, } from './utils';
6
+ import { vi } from 'vitest';
6
7
  describe('createMutation', () => {
7
8
  const queryCache = new QueryCache();
8
9
  const mutationCache = new MutationCache();
@@ -63,8 +64,8 @@ describe('createMutation', () => {
63
64
  });
64
65
  it('should be able to call `onSuccess` and `onSettled` after each successful mutate', async () => {
65
66
  const [count, setCount] = createSignal(0);
66
- const onSuccessMock = jest.fn();
67
- const onSettledMock = jest.fn();
67
+ const onSuccessMock = vi.fn();
68
+ const onSettledMock = vi.fn();
68
69
  function Page() {
69
70
  const mutation = createMutation(() => ({
70
71
  mutationFn: (vars) => Promise.resolve(vars.count),
@@ -110,7 +111,7 @@ describe('createMutation', () => {
110
111
  });
111
112
  it('should set correct values for `failureReason` and `failureCount` on multiple mutate calls', async () => {
112
113
  const [count, setCount] = createSignal(0);
113
- const mutateFn = jest.fn();
114
+ const mutateFn = vi.fn();
114
115
  mutateFn.mockImplementationOnce(() => {
115
116
  return Promise.reject(new Error('Error test Jonas'));
116
117
  });
@@ -152,8 +153,8 @@ describe('createMutation', () => {
152
153
  await waitFor(() => screen.getByText('Failed because null'));
153
154
  });
154
155
  it('should be able to call `onError` and `onSettled` after each failed mutate', async () => {
155
- const onErrorMock = jest.fn();
156
- const onSettledMock = jest.fn();
156
+ const onErrorMock = vi.fn();
157
+ const onSettledMock = vi.fn();
157
158
  const [count, setCount] = createSignal(0);
158
159
  function Page() {
159
160
  const mutation = createMutation(() => ({
@@ -388,7 +389,7 @@ describe('createMutation', () => {
388
389
  });
389
390
  it('should call onMutate even if paused', async () => {
390
391
  const onlineMock = mockNavigatorOnLine(false);
391
- const onMutate = jest.fn();
392
+ const onMutate = vi.fn();
392
393
  let count = 0;
393
394
  function Page() {
394
395
  const mutation = createMutation(() => ({
@@ -617,8 +618,8 @@ describe('createMutation', () => {
617
618
  });
618
619
  });
619
620
  it('should pass meta to mutation', async () => {
620
- const errorMock = jest.fn();
621
- const successMock = jest.fn();
621
+ const errorMock = vi.fn();
622
+ const successMock = vi.fn();
622
623
  const queryClientMutationMeta = createQueryClient({
623
624
  mutationCache: new MutationCache({
624
625
  onSuccess: (_, __, ___, mutation) => {
@@ -664,10 +665,10 @@ describe('createMutation', () => {
664
665
  expect(errorMock).toHaveBeenCalledWith(metaErrorMessage);
665
666
  });
666
667
  it('should call cache callbacks when unmounted', async () => {
667
- const onSuccess = jest.fn();
668
- const onSuccessMutate = jest.fn();
669
- const onSettled = jest.fn();
670
- const onSettledMutate = jest.fn();
668
+ const onSuccess = vi.fn();
669
+ const onSuccessMutate = vi.fn();
670
+ const onSettled = vi.fn();
671
+ const onSettledMutate = vi.fn();
671
672
  const mutationKey = queryKey();
672
673
  let count = 0;
673
674
  function Page() {
@@ -718,10 +719,10 @@ describe('createMutation', () => {
718
719
  expect(onSettledMutate).toHaveBeenCalledTimes(0);
719
720
  });
720
721
  it('should call mutate callbacks only for the last observer', async () => {
721
- const onSuccess = jest.fn();
722
- const onSuccessMutate = jest.fn();
723
- const onSettled = jest.fn();
724
- const onSettledMutate = jest.fn();
722
+ const onSuccess = vi.fn();
723
+ const onSuccessMutate = vi.fn();
724
+ const onSettled = vi.fn();
725
+ const onSettledMutate = vi.fn();
725
726
  let count = 0;
726
727
  function Page() {
727
728
  const mutation = createMutation(() => ({
@@ -762,7 +763,7 @@ describe('createMutation', () => {
762
763
  });
763
764
  it('should go to error state if onSuccess callback errors', async () => {
764
765
  const error = new Error('error from onSuccess');
765
- const onError = jest.fn();
766
+ const onError = vi.fn();
766
767
  function Page() {
767
768
  const mutation = createMutation(() => ({
768
769
  mutationFn: async (_text) => {
@@ -815,7 +816,7 @@ describe('createMutation', () => {
815
816
  it('should go to error state if onSettled callback errors', async () => {
816
817
  const error = new Error('error from onSettled');
817
818
  const mutateFnError = new Error('mutateFnError');
818
- const onError = jest.fn();
819
+ const onError = vi.fn();
819
820
  function Page() {
820
821
  const mutation = createMutation(() => ({
821
822
  mutationFn: async (_text) => {
@@ -3,6 +3,7 @@ import * as QueriesObserverModule from '../../../query-core/src/queriesObserver'
3
3
  import { createRenderEffect, createSignal } from 'solid-js';
4
4
  import { createQueries, QueriesObserver, QueryCache, QueryClientProvider, } from '..';
5
5
  import { createQueryClient, expectType, expectTypeNotAny, queryKey, sleep, } from './utils';
6
+ import { vi } from 'vitest';
6
7
  describe('useQueries', () => {
7
8
  const queryCache = new QueryCache();
8
9
  const queryClient = createQueryClient({ queryCache });
@@ -620,7 +621,7 @@ describe('useQueries', () => {
620
621
  return () => void 0;
621
622
  }
622
623
  }
623
- const QueriesObserverSpy = jest
624
+ const QueriesObserverSpy = vi
624
625
  .spyOn(QueriesObserverModule, 'QueriesObserver')
625
626
  .mockImplementation((fn) => {
626
627
  return new QueriesObserverMock(fn);
@@ -657,20 +658,4 @@ describe('useQueries', () => {
657
658
  await sleep(20);
658
659
  QueriesObserverSpy.mockRestore();
659
660
  });
660
- it('should use provided custom queryClient', async () => {
661
- const key = queryKey();
662
- const queryFn = () => {
663
- return Promise.resolve('custom client');
664
- };
665
- function Page() {
666
- const state = createQueries(() => ({
667
- queries: [{ queryKey: key, queryFn }],
668
- }), () => queryClient);
669
- return (<div>
670
- <h1>Status: {state[0].data}</h1>
671
- </div>);
672
- }
673
- render(() => <Page />);
674
- await waitFor(() => screen.getByText('Status: custom client'));
675
- });
676
661
  });
@@ -3,6 +3,7 @@ import { createEffect, createMemo, createRenderEffect, createSignal, ErrorBounda
3
3
  import { fireEvent, render, screen, waitFor } from 'solid-testing-library';
4
4
  import { createQuery, QueryCache, QueryClientProvider, keepPreviousData, } from '..';
5
5
  import { Blink, createQueryClient, expectType, mockNavigatorOnLine, mockVisibilityState, queryKey, setActTimeout, sleep, } from './utils';
6
+ import { vi } from 'vitest';
6
7
  describe('createQuery', () => {
7
8
  const queryCache = new QueryCache();
8
9
  const queryClient = createQueryClient({ queryCache });
@@ -361,7 +362,7 @@ describe('createQuery', () => {
361
362
  it('should call onSuccess after a query has been fetched', async () => {
362
363
  const key = queryKey();
363
364
  const states = [];
364
- const onSuccess = jest.fn();
365
+ const onSuccess = vi.fn();
365
366
  function Page() {
366
367
  const state = createQuery(() => ({
367
368
  queryKey: key,
@@ -387,7 +388,7 @@ describe('createQuery', () => {
387
388
  it('should call onSuccess after a disabled query has been fetched', async () => {
388
389
  const key = queryKey();
389
390
  const states = [];
390
- const onSuccess = jest.fn();
391
+ const onSuccess = vi.fn();
391
392
  function Page() {
392
393
  const state = createQuery(() => ({
393
394
  queryKey: key,
@@ -416,7 +417,7 @@ describe('createQuery', () => {
416
417
  it('should not call onSuccess if a component has unmounted', async () => {
417
418
  const key = queryKey();
418
419
  const states = [];
419
- const onSuccess = jest.fn();
420
+ const onSuccess = vi.fn();
420
421
  function Page() {
421
422
  const [show, setShow] = createSignal(true);
422
423
  createEffect(() => {
@@ -448,7 +449,7 @@ describe('createQuery', () => {
448
449
  it('should call onError after a query has been fetched with an error', async () => {
449
450
  const key = queryKey();
450
451
  const states = [];
451
- const onError = jest.fn();
452
+ const onError = vi.fn();
452
453
  function Page() {
453
454
  const state = createQuery(() => ({
454
455
  queryKey: key,
@@ -471,7 +472,7 @@ describe('createQuery', () => {
471
472
  });
472
473
  it('should not call onError when receiving a CancelledError', async () => {
473
474
  const key = queryKey();
474
- const onError = jest.fn();
475
+ const onError = vi.fn();
475
476
  function Page() {
476
477
  const state = createQuery(() => ({
477
478
  queryKey: key,
@@ -497,7 +498,7 @@ describe('createQuery', () => {
497
498
  it('should call onSettled after a query has been fetched', async () => {
498
499
  const key = queryKey();
499
500
  const states = [];
500
- const onSettled = jest.fn();
501
+ const onSettled = vi.fn();
501
502
  function Page() {
502
503
  const state = createQuery(() => ({
503
504
  queryKey: key,
@@ -520,7 +521,7 @@ describe('createQuery', () => {
520
521
  it('should call onSettled after a query has been fetched with an error', async () => {
521
522
  const key = queryKey();
522
523
  const states = [];
523
- const onSettled = jest.fn();
524
+ const onSettled = vi.fn();
524
525
  function Page() {
525
526
  const state = createQuery(() => ({
526
527
  queryKey: key,
@@ -1887,7 +1888,7 @@ describe('createQuery', () => {
1887
1888
  });
1888
1889
  it('should not refetch query on focus when `enabled` is set to `false`', async () => {
1889
1890
  const key = queryKey();
1890
- const queryFn = jest.fn().mockReturnValue('data');
1891
+ const queryFn = vi.fn().mockReturnValue('data');
1891
1892
  function Page() {
1892
1893
  const { data = 'default' } = createQuery(() => ({
1893
1894
  queryKey: key,
@@ -2523,7 +2524,7 @@ describe('createQuery', () => {
2523
2524
  });
2524
2525
  it('should retry specified number of times', async () => {
2525
2526
  const key = queryKey();
2526
- const queryFn = jest.fn();
2527
+ const queryFn = vi.fn();
2527
2528
  queryFn.mockImplementation(() => {
2528
2529
  return Promise.reject(new Error('Error test Barrett'));
2529
2530
  });
@@ -2552,7 +2553,7 @@ describe('createQuery', () => {
2552
2553
  });
2553
2554
  it('should not retry if retry function `false`', async () => {
2554
2555
  const key = queryKey();
2555
- const queryFn = jest.fn();
2556
+ const queryFn = vi.fn();
2556
2557
  queryFn.mockImplementationOnce(() => {
2557
2558
  return Promise.reject(new Error('Error test Tanner'));
2558
2559
  });
@@ -2585,7 +2586,7 @@ describe('createQuery', () => {
2585
2586
  });
2586
2587
  it('should extract retryDelay from error', async () => {
2587
2588
  const key = queryKey();
2588
- const queryFn = jest.fn();
2589
+ const queryFn = vi.fn();
2589
2590
  queryFn.mockImplementation(() => {
2590
2591
  return Promise.reject({ delay: 50 });
2591
2592
  });
@@ -2747,9 +2748,9 @@ describe('createQuery', () => {
2747
2748
  it('should refetch if stale after a prefetch', async () => {
2748
2749
  const key = queryKey();
2749
2750
  const states = [];
2750
- const queryFn = jest.fn();
2751
+ const queryFn = vi.fn();
2751
2752
  queryFn.mockImplementation(() => 'data');
2752
- const prefetchQueryFn = jest.fn();
2753
+ const prefetchQueryFn = vi.fn();
2753
2754
  prefetchQueryFn.mockImplementation(() => 'not yet...');
2754
2755
  await queryClient.prefetchQuery({
2755
2756
  queryKey: key,
@@ -2773,9 +2774,9 @@ describe('createQuery', () => {
2773
2774
  });
2774
2775
  it('should not refetch if not stale after a prefetch', async () => {
2775
2776
  const key = queryKey();
2776
- const queryFn = jest.fn();
2777
+ const queryFn = vi.fn();
2777
2778
  queryFn.mockImplementation(() => 'data');
2778
- const prefetchQueryFn = jest.fn();
2779
+ const prefetchQueryFn = vi.fn();
2779
2780
  prefetchQueryFn.mockImplementation(async () => {
2780
2781
  await sleep(10);
2781
2782
  return 'not yet...';
@@ -2977,7 +2978,7 @@ describe('createQuery', () => {
2977
2978
  });
2978
2979
  it('it should support enabled:false in query object syntax', async () => {
2979
2980
  const key = queryKey();
2980
- const queryFn = jest.fn();
2981
+ const queryFn = vi.fn();
2981
2982
  queryFn.mockImplementation(() => 'data');
2982
2983
  function Page() {
2983
2984
  const { fetchStatus } = createQuery(() => ({
@@ -3028,7 +3029,7 @@ describe('createQuery', () => {
3028
3029
  <Page />
3029
3030
  </QueryClientProvider>));
3030
3031
  await waitFor(() => screen.getByText('fetched data'));
3031
- const setTimeoutSpy = jest.spyOn(window, 'setTimeout');
3032
+ const setTimeoutSpy = vi.spyOn(window, 'setTimeout');
3032
3033
  result.unmount();
3033
3034
  expect(setTimeoutSpy).not.toHaveBeenCalled();
3034
3035
  });
@@ -3046,14 +3047,14 @@ describe('createQuery', () => {
3046
3047
  <Page />
3047
3048
  </QueryClientProvider>));
3048
3049
  await waitFor(() => screen.getByText('fetched data'));
3049
- const setTimeoutSpy = jest.spyOn(window, 'setTimeout');
3050
+ const setTimeoutSpy = vi.spyOn(window, 'setTimeout');
3050
3051
  result.unmount();
3051
3052
  expect(setTimeoutSpy).toHaveBeenLastCalledWith(expect.any(Function), 1000 * 60 * 10);
3052
3053
  });
3053
3054
  it('should not cause memo churn when data does not change', async () => {
3054
3055
  const key = queryKey();
3055
- const queryFn = jest.fn().mockReturnValue('data');
3056
- const memoFn = jest.fn();
3056
+ const queryFn = vi.fn().mockReturnValue('data');
3057
+ const memoFn = vi.fn();
3057
3058
  function Page() {
3058
3059
  const result = createQuery(() => ({
3059
3060
  queryKey: key,
@@ -3234,7 +3235,7 @@ describe('createQuery', () => {
3234
3235
  });
3235
3236
  it('should refetch if any query instance becomes enabled', async () => {
3236
3237
  const key = queryKey();
3237
- const queryFn = jest.fn().mockReturnValue('data');
3238
+ const queryFn = vi.fn().mockReturnValue('data');
3238
3239
  function Disabled() {
3239
3240
  createQuery(() => ({ queryKey: key, queryFn, enabled: false }));
3240
3241
  return null;
@@ -3504,10 +3505,10 @@ describe('createQuery', () => {
3504
3505
  });
3505
3506
  it('should cancel the query function when there are no more subscriptions', async () => {
3506
3507
  const key = queryKey();
3507
- let cancelFn = jest.fn();
3508
+ let cancelFn = vi.fn();
3508
3509
  const queryFn = ({ signal }) => {
3509
3510
  const promise = new Promise((resolve, reject) => {
3510
- cancelFn = jest.fn(() => reject('Cancelled'));
3511
+ cancelFn = vi.fn(() => reject('Cancelled'));
3511
3512
  signal?.addEventListener('abort', cancelFn);
3512
3513
  sleep(20).then(() => resolve('OK'));
3513
3514
  });
@@ -3767,7 +3768,7 @@ describe('createQuery', () => {
3767
3768
  expect(renders).toBe(hashes);
3768
3769
  });
3769
3770
  it('should refetch when changed enabled to true in error state', async () => {
3770
- const queryFn = jest.fn();
3771
+ const queryFn = vi.fn();
3771
3772
  queryFn.mockImplementation(async () => {
3772
3773
  await sleep(10);
3773
3774
  return Promise.reject(new Error('Suspense Error Bingo'));
@@ -4514,7 +4515,7 @@ describe('createQuery', () => {
4514
4515
  });
4515
4516
  it('setQueryData - should not call onSuccess callback of active observers', async () => {
4516
4517
  const key = queryKey();
4517
- const onSuccess = jest.fn();
4518
+ const onSuccess = vi.fn();
4518
4519
  function Page() {
4519
4520
  const state = createQuery(() => ({
4520
4521
  queryKey: key,
@@ -2,6 +2,7 @@ import { fireEvent, render, screen, waitFor } from 'solid-testing-library';
2
2
  import { createRenderEffect, createSignal, ErrorBoundary, on, Show, Suspense, } from 'solid-js';
3
3
  import { createInfiniteQuery, createQuery, QueryCache, QueryClientProvider, } from '..';
4
4
  import { createQueryClient, queryKey, sleep } from './utils';
5
+ import { vi } from 'vitest';
5
6
  describe("useQuery's in Suspense mode", () => {
6
7
  const queryCache = new QueryCache();
7
8
  const queryClient = createQueryClient({ queryCache });
@@ -91,7 +92,7 @@ describe("useQuery's in Suspense mode", () => {
91
92
  });
92
93
  it('should not call the queryFn twice when used in Suspense mode', async () => {
93
94
  const key = queryKey();
94
- const queryFn = jest.fn();
95
+ const queryFn = vi.fn();
95
96
  queryFn.mockImplementation(() => {
96
97
  sleep(10);
97
98
  return 'data';
@@ -141,7 +142,7 @@ describe("useQuery's in Suspense mode", () => {
141
142
  });
142
143
  it('should call onSuccess on the first successful call', async () => {
143
144
  const key = queryKey();
144
- const successFn = jest.fn();
145
+ const successFn = vi.fn();
145
146
  function Page() {
146
147
  createQuery(() => ({
147
148
  queryKey: [key],
@@ -166,8 +167,8 @@ describe("useQuery's in Suspense mode", () => {
166
167
  });
167
168
  it('should call every onSuccess handler within a suspense boundary', async () => {
168
169
  const key = queryKey();
169
- const successFn1 = jest.fn();
170
- const successFn2 = jest.fn();
170
+ const successFn1 = vi.fn();
171
+ const successFn2 = vi.fn();
171
172
  function FirstComponent() {
172
173
  createQuery(() => ({
173
174
  queryKey: key,
@@ -514,7 +515,7 @@ describe("useQuery's in Suspense mode", () => {
514
515
  });
515
516
  it('should not call the queryFn when not enabled', async () => {
516
517
  const key = queryKey();
517
- const queryFn = jest.fn();
518
+ const queryFn = vi.fn();
518
519
  queryFn.mockImplementation(async () => {
519
520
  await sleep(10);
520
521
  return '23';
@@ -5,6 +5,7 @@ import { createEffect, createRenderEffect, createSignal, Show } from 'solid-js';
5
5
  import { render } from 'solid-testing-library';
6
6
  import * as MutationCacheModule from '../../../query-core/src/mutationCache';
7
7
  import { setActTimeout } from './utils';
8
+ import { vi } from 'vitest';
8
9
  describe('useIsMutating', () => {
9
10
  it('should return the number of fetching mutations', async () => {
10
11
  const isMutatings = [];
@@ -126,6 +127,27 @@ describe('useIsMutating', () => {
126
127
  // Again, No unnecessary re-renders like React
127
128
  await waitFor(() => expect(isMutatings).toEqual([0, 1, 0]));
128
129
  });
130
+ it('should use provided custom queryClient', async () => {
131
+ const queryClient = createQueryClient();
132
+ function Page() {
133
+ const isMutating = useIsMutating(undefined, () => queryClient);
134
+ const { mutate } = createMutation(() => ({
135
+ mutationKey: ['mutation1'],
136
+ mutationFn: async () => {
137
+ await sleep(10);
138
+ return 'data';
139
+ },
140
+ }), () => queryClient);
141
+ createEffect(() => {
142
+ mutate();
143
+ });
144
+ return (<div>
145
+ <div>mutating: {isMutating}</div>
146
+ </div>);
147
+ }
148
+ render(() => <Page></Page>);
149
+ await waitFor(() => screen.findByText('mutating: 1'));
150
+ });
129
151
  it('should not change state if unmounted', async () => {
130
152
  // We have to mock the MutationCache to not unsubscribe
131
153
  // the listener when the component is unmounted
@@ -135,7 +157,7 @@ describe('useIsMutating', () => {
135
157
  return () => void 0;
136
158
  }
137
159
  }
138
- const MutationCacheSpy = jest
160
+ const MutationCacheSpy = vi
139
161
  .spyOn(MutationCacheModule, 'MutationCache')
140
162
  .mockImplementation((fn) => {
141
163
  return new MutationCacheMock(fn);
@@ -173,25 +195,4 @@ describe('useIsMutating', () => {
173
195
  await sleep(20);
174
196
  MutationCacheSpy.mockRestore();
175
197
  });
176
- it('should use provided custom queryClient', async () => {
177
- const queryClient = createQueryClient();
178
- function Page() {
179
- const isMutating = useIsMutating(undefined, () => queryClient);
180
- const { mutate } = createMutation(() => ({
181
- mutationKey: ['mutation1'],
182
- mutationFn: async () => {
183
- await sleep(10);
184
- return 'data';
185
- },
186
- }), () => queryClient);
187
- createEffect(() => {
188
- mutate();
189
- });
190
- return (<div>
191
- <div>mutating: {isMutating}</div>
192
- </div>);
193
- }
194
- render(() => <Page></Page>);
195
- await waitFor(() => screen.findByText('mutating: 1'));
196
- });
197
198
  });
@@ -1,5 +1,6 @@
1
1
  import { QueryClient } from '@tanstack/query-core';
2
2
  import { createEffect, createSignal, onCleanup, Show } from 'solid-js';
3
+ import { vi } from 'vitest';
3
4
  let queryKeyCount = 0;
4
5
  export function queryKey() {
5
6
  queryKeyCount++;
@@ -20,10 +21,10 @@ export function createQueryClient(config) {
20
21
  return new QueryClient(config);
21
22
  }
22
23
  export function mockVisibilityState(value) {
23
- return jest.spyOn(document, 'visibilityState', 'get').mockReturnValue(value);
24
+ return vi.spyOn(document, 'visibilityState', 'get').mockReturnValue(value);
24
25
  }
25
26
  export function mockNavigatorOnLine(value) {
26
- return jest.spyOn(navigator, 'onLine', 'get').mockReturnValue(value);
27
+ return vi.spyOn(navigator, 'onLine', 'get').mockReturnValue(value);
27
28
  }
28
29
  export function sleep(timeout) {
29
30
  return new Promise((resolve, _reject) => {
@@ -1,4 +1,3 @@
1
- /// <reference types="jest" />
2
1
  /// <reference types="node" />
3
2
  import type { QueryClientConfig } from '@tanstack/query-core';
4
3
  import { QueryClient } from '@tanstack/query-core';
@@ -8,8 +7,8 @@ export declare const Blink: (props: {
8
7
  duration: number;
9
8
  } & ParentProps) => import("solid-js").JSX.Element;
10
9
  export declare function createQueryClient(config?: QueryClientConfig): QueryClient;
11
- export declare function mockVisibilityState(value: DocumentVisibilityState): jest.SpyInstance<DocumentVisibilityState, [], any>;
12
- export declare function mockNavigatorOnLine(value: boolean): jest.SpyInstance<boolean, [], any>;
10
+ export declare function mockVisibilityState(value: DocumentVisibilityState): import("vitest/dist/index-1cfc7f58").S<[], DocumentVisibilityState>;
11
+ export declare function mockNavigatorOnLine(value: boolean): import("vitest/dist/index-1cfc7f58").S<[], boolean>;
13
12
  export declare function sleep(timeout: number): Promise<void>;
14
13
  export declare function setActTimeout(fn: () => void, ms?: number): NodeJS.Timeout;
15
14
  /**