Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -1523,18 +1523,17 @@ describe('useInfiniteQuery', () => {
refetch,
} = useInfiniteQuery({
queryKey: key,
queryFn: async ({ pageParam }): Promise<Result> => {
await sleep(10)
queryFn: ({ pageParam }): Promise<Result> => {
const noNext =
pageParam === MAX || (pageParam === MAX - 1 && isRemovedLastPage)
return {
return sleep(10).then(() => ({
items: [...new Array(10)]
.fill(null)
.map((_, d) => pageParam * pageSize + d),
nextId: noNext ? undefined : pageParam + 1,
prevId: pageParam - 1,
ts: fetchCountRef.current++,
}
}))
},
getNextPageParam: (lastPage) => lastPage.nextId,
initialPageParam: 0,
Expand Down
114 changes: 57 additions & 57 deletions packages/preact-query/src/__tests__/useMutation.test.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -210,7 +210,7 @@ describe('useMutation', () => {

function Page() {
const { mutateAsync } = useMutation({
mutationFn: async (_text: string) =>
mutationFn: (_text: string) =>
sleep(10).then(() => {
throw new Error('oops')
}),
Expand DownExpand Up@@ -370,7 +370,7 @@ describe('useMutation', () => {

function Page() {
const { mutateAsync } = useMutation({
mutationFn: async (_text: string) =>
mutationFn: (_text: string) =>
sleep(10).then(() => {
throw new Error('oops')
}),
Expand DownExpand Up@@ -740,7 +740,7 @@ describe('useMutation', () => {

function Page() {
const { mutateAsync } = useMutation({
mutationFn: async (_text: string) =>
mutationFn: (_text: string) =>
sleep(10).then(() => {
throw new Error('oops')
}),
Expand DownExpand Up@@ -860,7 +860,7 @@ describe('useMutation', () => {

function Page() {
const { mutateAsync } = useMutation({
mutationFn: async (_text: string) => Promise.reject(new Error('oops')),
mutationFn: (_text: string) => Promise.reject(new Error('oops')),
onError: () => {
callbacks.push('useMutation.onError')
return Promise.resolve()
Expand DownExpand Up@@ -911,7 +911,7 @@ describe('useMutation', () => {

function Page() {
const { mutate } = useMutation({
mutationFn: async (_text: string) =>
mutationFn: (_text: string) =>
sleep(10).then(() => Promise.reject(new Error('oops'))),
onError: () => {
callbacks.push('useMutation.onError')
Expand DownExpand Up@@ -1238,13 +1238,13 @@ describe('useMutation', () => {
function Page() {
const state = useMutation({
mutationKey: key,
mutationFn: async (_text: string) => {
await sleep(10)
count++
return count > 1
? Promise.resolve(`data${count}`)
: Promise.reject(new Error('oops'))
},
mutationFn: (_text: string) =>
sleep(10).then(() => {
count++
return count > 1
? Promise.resolve(`data${count}`)
: Promise.reject(new Error('oops'))
}),
retry: 1,
retryDelay: 5,
networkMode: 'offlineFirst',
Expand DownExpand Up@@ -1808,10 +1808,10 @@ describe('useMutation', () => {

function Page() {
const mutation = useMutation({
mutationFn: async (_text: string) => {
await sleep(10)
throw mutateFnError
},
mutationFn: (_text: string) =>
sleep(10).then(() => {
throw mutateFnError
}),
onError: () => Promise.reject(error),
})

Expand DownExpand Up@@ -1854,10 +1854,10 @@ describe('useMutation', () => {

function Page() {
const mutation = useMutation({
mutationFn: async (_text: string) => {
await sleep(10)
throw mutateFnError
},
mutationFn: (_text: string) =>
sleep(10).then(() => {
throw mutateFnError
}),
onSettled: () => Promise.reject(error),
onError,
})
Expand DownExpand Up@@ -1895,7 +1895,7 @@ describe('useMutation', () => {
function Page() {
const mutation = useMutation(
{
mutationFn: async (text: string) => {
mutationFn: (text: string) => {
return Promise.resolve(text)
},
},
Expand DownExpand Up@@ -2017,13 +2017,13 @@ describe('useMutation', () => {
const [message, setMessage] = useState<string>('idle')

const { mutate } = useMutation({
mutationFn: async (shouldFail: boolean) => {
await sleep(10)
if (shouldFail) {
throw new Error('submission failed')
}
return 'submitted successfully'
},
mutationFn: (shouldFail: boolean) =>
sleep(10).then(() => {
if (shouldFail) {
throw new Error('submission failed')
}
return 'submitted successfully'
}),
retry: false,
})

Expand DownExpand Up@@ -2059,13 +2059,13 @@ describe('useMutation', () => {
const [message, setMessage] = useState<string>('idle')

const { mutate } = useMutation({
mutationFn: async (shouldFail: boolean) => {
await sleep(10)
if (shouldFail) {
throw new Error('submission failed')
}
return 'submitted successfully'
},
mutationFn: (shouldFail: boolean) =>
sleep(10).then(() => {
if (shouldFail) {
throw new Error('submission failed')
}
return 'submitted successfully'
}),
retry: false,
})

Expand DownExpand Up@@ -2103,14 +2103,14 @@ describe('useMutation', () => {
const [message, setMessage] = useState<string>('idle')

const { mutate } = useMutation({
mutationFn: async () => {
await sleep(10)
attempt++
if (attempt < 2) {
throw new Error('temporary failure')
}
return 'success'
},
mutationFn: () =>
sleep(10).then(() => {
attempt++
if (attempt < 2) {
throw new Error('temporary failure')
}
return 'success'
}),
retry: false,
})

Expand DownExpand Up@@ -2309,13 +2309,13 @@ describe('useMutation', () => {
const [result, setResult] = useState<string>('idle')

const { mutateAsync } = useMutation({
mutationFn: async (file: string) => {
await sleep(10)
if (file === 'file2') {
throw new Error('upload failed')
}
return `uploaded: ${file}`
},
mutationFn: (file: string) =>
sleep(10).then(() => {
if (file === 'file2') {
throw new Error('upload failed')
}
return `uploaded: ${file}`
}),
retry: false,
})

Expand DownExpand Up@@ -2357,13 +2357,13 @@ describe('useMutation', () => {
const [result, setResult] = useState<string>('idle')

const { mutateAsync } = useMutation({
mutationFn: async (file: string) => {
await sleep(10)
if (file === 'file2') {
throw new Error('upload failed')
}
return `uploaded: ${file}`
},
mutationFn: (file: string) =>
sleep(10).then(() => {
if (file === 'file2') {
throw new Error('upload failed')
}
return `uploaded: ${file}`
}),
retry: false,
})

Expand Down
34 changes: 17 additions & 17 deletions packages/preact-query/src/__tests__/useQueries.test.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -74,11 +74,11 @@ describe('useQueries', () => {
queries: [
{
queryKey: key1,
queryFn: async () => {
await sleep(10)
count++
return count
},
queryFn: () =>
sleep(10).then(() => {
count++
return count
}),
},
],
})
Expand DownExpand Up@@ -145,7 +145,7 @@ describe('useQueries', () => {
},
{
queryKey: key4,
queryFn: async () =>
queryFn: () =>
Promise.reject(
new Error('this should not throw because query#2 already did'),
),
Expand DownExpand Up@@ -213,7 +213,7 @@ describe('useQueries', () => {
},
{
queryKey: key4,
queryFn: async () =>
queryFn: () =>
Promise.reject(
new Error('this should not throw because query#3 already did'),
),
Expand DownExpand Up@@ -769,19 +769,19 @@ describe('useQueries', () => {
queries: [
{
queryKey: [key1],
queryFn: async () => {
await sleep(10)
queryFns.push('first result')
return 'first result'
},
queryFn: () =>
sleep(10).then(() => {
queryFns.push('first result')
return 'first result'
}),
},
{
queryKey: [key2],
queryFn: async () => {
await sleep(20)
queryFns.push('second result')
return 'second result'
},
queryFn: () =>
sleep(20).then(() => {
queryFns.push('second result')
return 'second result'
}),
},
],
combine: () => 'foo',
Expand Down
Loading
Loading