Skip to content

Commit 522b081

Browse files
authored
test(*): remove unnecessary async (#9026)
1 parent f812bf4 commit 522b081

File tree

4 files changed

+32
-32
lines changed

4 files changed

+32
-32
lines changed

packages/solid-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const createMockPersister = (): Persister => {
1515
let storedState: PersistedClient | undefined
1616

1717
return {
18-
async persistClient(persistClient: PersistedClient) {
18+
persistClient(persistClient: PersistedClient) {
1919
storedState = persistClient
2020
},
2121
async restoreClient() {

packages/solid-query/src/__tests__/useMutation.test.tsx

+12-12
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,11 @@ describe('useMutation', () => {
316316

317317
function Page() {
318318
const mutation = useMutation(() => ({
319-
mutationFn: async (text: string) => text,
320-
onSuccess: async () => {
319+
mutationFn: (text: string) => Promise.resolve(text),
320+
onSuccess: () => {
321321
callbacks.push('useMutation.onSuccess')
322322
},
323-
onSettled: async () => {
323+
onSettled: () => {
324324
callbacks.push('useMutation.onSettled')
325325
},
326326
}))
@@ -330,10 +330,10 @@ describe('useMutation', () => {
330330
setActTimeout(async () => {
331331
try {
332332
const result = await mutateAsync('todo', {
333-
onSuccess: async () => {
333+
onSuccess: () => {
334334
callbacks.push('mutateAsync.onSuccess')
335335
},
336-
onSettled: async () => {
336+
onSettled: () => {
337337
callbacks.push('mutateAsync.onSettled')
338338
},
339339
})
@@ -369,10 +369,10 @@ describe('useMutation', () => {
369369
const mutation = useMutation(() => ({
370370
mutationFn: async (_text: string) => Promise.reject(new Error('oops')),
371371

372-
onError: async () => {
372+
onError: () => {
373373
callbacks.push('useMutation.onError')
374374
},
375-
onSettled: async () => {
375+
onSettled: () => {
376376
callbacks.push('useMutation.onSettled')
377377
},
378378
}))
@@ -382,10 +382,10 @@ describe('useMutation', () => {
382382
setActTimeout(async () => {
383383
try {
384384
await mutateAsync('todo', {
385-
onError: async () => {
385+
onError: () => {
386386
callbacks.push('mutateAsync.onError')
387387
},
388-
onSettled: async () => {
388+
onSettled: () => {
389389
callbacks.push('mutateAsync.onSettled')
390390
},
391391
})
@@ -756,7 +756,7 @@ describe('useMutation', () => {
756756
})
757757
})
758758

759-
it('should not change state if unmounted', async () => {
759+
it('should not change state if unmounted', () => {
760760
function Mutates() {
761761
const mutation = useMutation(() => ({ mutationFn: () => sleep(10) }))
762762
return <button onClick={() => mutation.mutate()}>mutate</button>
@@ -901,11 +901,11 @@ describe('useMutation', () => {
901901

902902
function Page() {
903903
const mutationSucceed = useMutation(() => ({
904-
mutationFn: async () => '',
904+
mutationFn: () => Promise.resolve(''),
905905
meta: { metaSuccessMessage },
906906
}))
907907
const mutationError = useMutation(() => ({
908-
mutationFn: async () => {
908+
mutationFn: () => {
909909
throw new Error('')
910910
},
911911
meta: { metaErrorMessage },

packages/solid-query/src/__tests__/useQueries.test.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe('useQueries', () => {
6969
expect(results[2]).toMatchObject([{ data: 1 }, { data: 2 }])
7070
})
7171

72-
it('handles type parameter - tuple of tuples', async () => {
72+
it('handles type parameter - tuple of tuples', () => {
7373
const key1 = queryKey()
7474
const key2 = queryKey()
7575
const key3 = queryKey()
@@ -174,7 +174,7 @@ describe('useQueries', () => {
174174
}
175175
})
176176

177-
it('handles type parameter - tuple of objects', async () => {
177+
it('handles type parameter - tuple of objects', () => {
178178
const key1 = queryKey()
179179
const key2 = queryKey()
180180
const key3 = queryKey()
@@ -315,7 +315,7 @@ describe('useQueries', () => {
315315
}
316316
})
317317

318-
it('handles array literal without type parameter to infer result type', async () => {
318+
it('handles array literal without type parameter to infer result type', () => {
319319
const key1 = queryKey()
320320
const key2 = queryKey()
321321
const key3 = queryKey()
@@ -544,7 +544,7 @@ describe('useQueries', () => {
544544
type QueryKeyA = ['queryA']
545545
const getQueryKeyA = (): QueryKeyA => ['queryA']
546546
type GetQueryFunctionA = () => QueryFunction<number, QueryKeyA>
547-
const getQueryFunctionA: GetQueryFunctionA = () => async () => {
547+
const getQueryFunctionA: GetQueryFunctionA = () => () => {
548548
return 1
549549
}
550550
type SelectorA = (data: number) => [number, string]
@@ -553,7 +553,7 @@ describe('useQueries', () => {
553553
type QueryKeyB = ['queryB', string]
554554
const getQueryKeyB = (id: string): QueryKeyB => ['queryB', id]
555555
type GetQueryFunctionB = () => QueryFunction<string, QueryKeyB>
556-
const getQueryFunctionB: GetQueryFunctionB = () => async () => {
556+
const getQueryFunctionB: GetQueryFunctionB = () => () => {
557557
return '1'
558558
}
559559
type SelectorB = (data: string) => [string, number]

packages/solid-query/src/__tests__/useQuery.test.tsx

+14-14
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe('useQuery', () => {
7272
// it should provide the result type in the configuration
7373
useQuery(() => ({
7474
queryKey: [key],
75-
queryFn: async () => true,
75+
queryFn: () => true,
7676
}))
7777

7878
// it should be possible to specify a union type as result type
@@ -117,7 +117,7 @@ describe('useQuery', () => {
117117
type MyData = number
118118
type MyQueryKey = readonly ['my-data', number]
119119

120-
const getMyDataArrayKey: QueryFunction<MyData, MyQueryKey> = async ({
120+
const getMyDataArrayKey: QueryFunction<MyData, MyQueryKey> = ({
121121
queryKey: [, n],
122122
}) => {
123123
return n + 42
@@ -128,9 +128,7 @@ describe('useQuery', () => {
128128
queryFn: getMyDataArrayKey,
129129
}))
130130

131-
const getMyDataStringKey: QueryFunction<MyData, ['1']> = async (
132-
context,
133-
) => {
131+
const getMyDataStringKey: QueryFunction<MyData, ['1']> = (context) => {
134132
expectTypeOf(context.queryKey).toEqualTypeOf<['1']>()
135133
return Number(context.queryKey[0]) + 42
136134
}
@@ -170,7 +168,7 @@ describe('useQuery', () => {
170168
queryFn: () => fetcher(qk[1], 'token'),
171169
...options,
172170
}))
173-
const test = useWrappedQuery([''], async () => '1')
171+
const test = useWrappedQuery([''], () => Promise.resolve('1'))
174172
expectTypeOf(test.data).toEqualTypeOf<string | undefined>()
175173

176174
// handles wrapped queries with custom fetcher passed directly to useQuery
@@ -188,7 +186,9 @@ describe('useQuery', () => {
188186
'safely'
189187
>,
190188
) => useQuery(() => ({ queryKey: qk, queryFn: fetcher, ...options }))
191-
const testFuncStyle = useWrappedFuncStyleQuery([''], async () => true)
189+
const testFuncStyle = useWrappedFuncStyleQuery([''], () =>
190+
Promise.resolve(true),
191+
)
192192
expectTypeOf(testFuncStyle.data).toEqualTypeOf<boolean | undefined>()
193193
}
194194
})
@@ -1854,7 +1854,7 @@ describe('useQuery', () => {
18541854
})
18551855

18561856
// See https://github.com/tannerlinsley/react-query/issues/137
1857-
it('should not override initial data in dependent queries', async () => {
1857+
it('should not override initial data in dependent queries', () => {
18581858
const key1 = queryKey()
18591859
const key2 = queryKey()
18601860

@@ -1895,7 +1895,7 @@ describe('useQuery', () => {
18951895
rendered.getByText('Second Status: success')
18961896
})
18971897

1898-
it('should update query options', async () => {
1898+
it('should update query options', () => {
18991899
const key = queryKey()
19001900

19011901
const queryFn = async () => {
@@ -2018,7 +2018,7 @@ describe('useQuery', () => {
20182018
})
20192019

20202020
// See https://github.com/tannerlinsley/react-query/issues/144
2021-
it('should be in "pending" state by default', async () => {
2021+
it('should be in "pending" state by default', () => {
20222022
const key = queryKey()
20232023

20242024
function Page() {
@@ -3403,7 +3403,7 @@ describe('useQuery', () => {
34033403

34043404
const query = useQuery<unknown, Error>(() => ({
34053405
queryKey: key,
3406-
queryFn: async () => {
3406+
queryFn: () => {
34073407
if (counter < 2) {
34083408
counter++
34093409
throw new Error('error')
@@ -3753,7 +3753,7 @@ describe('useQuery', () => {
37533753
expect(results[2]).toMatchObject({ data: 'fetched data', isStale: false })
37543754
})
37553755

3756-
it('should support enabled:false in query object syntax', async () => {
3756+
it('should support enabled:false in query object syntax', () => {
37573757
const key = queryKey()
37583758
const queryFn = vi.fn<(...args: Array<unknown>) => string>()
37593759
queryFn.mockImplementation(() => 'data')
@@ -5916,7 +5916,7 @@ describe('useQuery', () => {
59165916
const states: Array<UseQueryResult<unknown>> = []
59175917
const error = new Error('oops')
59185918

5919-
const queryFn = async (): Promise<unknown> => {
5919+
const queryFn = (): Promise<unknown> => {
59205920
throw error
59215921
}
59225922

@@ -5996,7 +5996,7 @@ describe('useQuery', () => {
59965996
function Page() {
59975997
const state = useQuery(() => ({
59985998
queryKey: key,
5999-
queryFn: async (): Promise<unknown> => {
5999+
queryFn: (): Promise<unknown> => {
60006000
throw error
60016001
},
60026002
retry: false,

0 commit comments

Comments
 (0)