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
34 changes: 17 additions & 17 deletions packages/preact-query/src/__tests__/useMutation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1898,11 +1898,11 @@ describe('useMutation', () => {
function Page() {
const [result, setResult] = useState<string>('idle')

const createUserMutation = useMutation({
const { mutateAsync: createUserAsync } = useMutation({
mutationFn: (name: string) => sleep(10).then(() => ({ id: '1', name })),
})

const updateProfileMutation = useMutation({
const { mutateAsync: updateProfileAsync } = useMutation({
mutationFn: (userId: string) =>
sleep(10).then(() => `profile updated for ${userId}`),
})
Expand All @@ -1911,8 +1911,8 @@ describe('useMutation', () => {
<div>
<button
onClick={async () => {
const user = await createUserMutation.mutateAsync('John')
const profile = await updateProfileMutation.mutateAsync(user.id)
const user = await createUserAsync('John')
const profile = await updateProfileAsync(user.id)
setResult(profile)
}}
>
Expand All @@ -1938,14 +1938,14 @@ describe('useMutation', () => {
function Page() {
const [result, setResult] = useState<string>('idle')

const createUserMutation = useMutation({
const { mutateAsync: createUserAsync } = useMutation({
mutationFn: (_name: string) =>
sleep(10).then<{ id: string }>(() => {
throw new Error('create failed')
}),
})

const updateProfileMutation = useMutation({
const { mutateAsync: updateProfileAsync } = useMutation({
mutationFn: (userId: string) =>
sleep(10).then(() => `profile updated for ${userId}`),
})
Expand All @@ -1955,8 +1955,8 @@ describe('useMutation', () => {
<button
onClick={async () => {
try {
const user = await createUserMutation.mutateAsync('John')
const profile = await updateProfileMutation.mutateAsync(user.id)
const user = await createUserAsync('John')
const profile = await updateProfileAsync(user.id)
setResult(profile)
} catch (error) {
setResult(`error: ${(error as Error).message}`)
Expand Down Expand Up @@ -1984,7 +1984,7 @@ describe('useMutation', () => {
function Page() {
const [message, setMessage] = useState<string>('idle')

const submitMutation = useMutation({
const { mutate } = useMutation({
mutationFn: async (shouldFail: boolean) => {
await sleep(10)
if (shouldFail) {
Expand All @@ -1999,7 +1999,7 @@ describe('useMutation', () => {
<div>
<button
onClick={() =>
submitMutation.mutate(false, {
mutate(false, {
onSuccess: (result) => setMessage(`success: ${result}`),
onError: (error) => setMessage(`error: ${error.message}`),
})
Expand All @@ -2009,7 +2009,7 @@ describe('useMutation', () => {
</button>
<button
onClick={() =>
submitMutation.mutate(true, {
mutate(true, {
onSuccess: (result) => setMessage(`success: ${result}`),
onError: (error) => setMessage(`error: ${error.message}`),
})
Expand Down Expand Up @@ -2045,7 +2045,7 @@ describe('useMutation', () => {
function Page() {
const [message, setMessage] = useState<string>('idle')

const submitMutation = useMutation({
const { mutate } = useMutation({
mutationFn: async () => {
await sleep(10)
attempt++
Expand All @@ -2061,7 +2061,7 @@ describe('useMutation', () => {
<div>
<button
onClick={() =>
submitMutation.mutate(undefined, {
mutate(undefined, {
onSuccess: (result) => setMessage(`result: ${result}`),
onError: () => setMessage('failed, retrying...'),
})
Expand Down Expand Up @@ -2099,7 +2099,7 @@ describe('useMutation', () => {

const [successMessage, setSuccessMessage] = useState<string>('')

const deleteMutation = useMutation({
const { mutate } = useMutation({
mutationFn: (item: string) => sleep(10).then(() => item),
onMutate: (item) => {
const previousItems = [...items]
Expand All @@ -2119,7 +2119,7 @@ describe('useMutation', () => {
return (
<div>
{items.map((item) => (
<button key={item} onClick={() => deleteMutation.mutate(item)}>
<button key={item} onClick={() => mutate(item)}>
delete {item}
</button>
))}
Expand Down Expand Up @@ -2156,7 +2156,7 @@ describe('useMutation', () => {

const [message, setMessage] = useState<string>('')

const deleteMutation = useMutation({
const { mutate } = useMutation({
mutationFn: (item: string) =>
sleep(10).then(() => {
throw new Error(`Failed to delete ${item}`)
Expand All @@ -2181,7 +2181,7 @@ describe('useMutation', () => {
return (
<div>
{items.map((item) => (
<button key={item} onClick={() => deleteMutation.mutate(item)}>
<button key={item} onClick={() => mutate(item)}>
delete {item}
</button>
))}
Expand Down
34 changes: 17 additions & 17 deletions packages/react-query/src/__tests__/useMutation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1897,11 +1897,11 @@ describe('useMutation', () => {
function Page() {
const [result, setResult] = React.useState<string>('idle')

const createUserMutation = useMutation({
const { mutateAsync: createUserAsync } = useMutation({
mutationFn: (name: string) => sleep(10).then(() => ({ id: '1', name })),
})

const updateProfileMutation = useMutation({
const { mutateAsync: updateProfileAsync } = useMutation({
mutationFn: (userId: string) =>
sleep(10).then(() => `profile updated for ${userId}`),
})
Expand All @@ -1910,8 +1910,8 @@ describe('useMutation', () => {
<div>
<button
onClick={async () => {
const user = await createUserMutation.mutateAsync('John')
const profile = await updateProfileMutation.mutateAsync(user.id)
const user = await createUserAsync('John')
const profile = await updateProfileAsync(user.id)
setResult(profile)
}}
>
Expand All @@ -1937,14 +1937,14 @@ describe('useMutation', () => {
function Page() {
const [result, setResult] = React.useState<string>('idle')

const createUserMutation = useMutation({
const { mutateAsync: createUserAsync } = useMutation({
mutationFn: (_name: string) =>
sleep(10).then<{ id: string }>(() => {
throw new Error('create failed')
}),
})

const updateProfileMutation = useMutation({
const { mutateAsync: updateProfileAsync } = useMutation({
mutationFn: (userId: string) =>
sleep(10).then(() => `profile updated for ${userId}`),
})
Expand All @@ -1954,8 +1954,8 @@ describe('useMutation', () => {
<button
onClick={async () => {
try {
const user = await createUserMutation.mutateAsync('John')
const profile = await updateProfileMutation.mutateAsync(user.id)
const user = await createUserAsync('John')
const profile = await updateProfileAsync(user.id)
setResult(profile)
} catch (error) {
setResult(`error: ${(error as Error).message}`)
Expand Down Expand Up @@ -1983,7 +1983,7 @@ describe('useMutation', () => {
function Page() {
const [message, setMessage] = React.useState<string>('idle')

const submitMutation = useMutation({
const { mutate } = useMutation({
mutationFn: async (shouldFail: boolean) => {
await sleep(10)
if (shouldFail) {
Expand All @@ -1998,7 +1998,7 @@ describe('useMutation', () => {
<div>
<button
onClick={() =>
submitMutation.mutate(false, {
mutate(false, {
onSuccess: (result) => setMessage(`success: ${result}`),
onError: (error) => setMessage(`error: ${error.message}`),
})
Expand All @@ -2008,7 +2008,7 @@ describe('useMutation', () => {
</button>
<button
onClick={() =>
submitMutation.mutate(true, {
mutate(true, {
onSuccess: (result) => setMessage(`success: ${result}`),
onError: (error) => setMessage(`error: ${error.message}`),
})
Expand Down Expand Up @@ -2044,7 +2044,7 @@ describe('useMutation', () => {
function Page() {
const [message, setMessage] = React.useState<string>('idle')

const submitMutation = useMutation({
const { mutate } = useMutation({
mutationFn: async () => {
await sleep(10)
attempt++
Expand All @@ -2060,7 +2060,7 @@ describe('useMutation', () => {
<div>
<button
onClick={() =>
submitMutation.mutate(undefined, {
mutate(undefined, {
onSuccess: (result) => setMessage(`result: ${result}`),
onError: () => setMessage('failed, retrying...'),
})
Expand Down Expand Up @@ -2098,7 +2098,7 @@ describe('useMutation', () => {

const [successMessage, setSuccessMessage] = React.useState<string>('')

const deleteMutation = useMutation({
const { mutate } = useMutation({
mutationFn: (item: string) => sleep(10).then(() => item),
onMutate: (item) => {
const previousItems = [...items]
Expand All @@ -2118,7 +2118,7 @@ describe('useMutation', () => {
return (
<div>
{items.map((item) => (
<button key={item} onClick={() => deleteMutation.mutate(item)}>
<button key={item} onClick={() => mutate(item)}>
delete {item}
</button>
))}
Expand Down Expand Up @@ -2155,7 +2155,7 @@ describe('useMutation', () => {

const [message, setMessage] = React.useState<string>('')

const deleteMutation = useMutation({
const { mutate } = useMutation({
mutationFn: (item: string) =>
sleep(10).then(() => {
throw new Error(`Failed to delete ${item}`)
Expand All @@ -2180,7 +2180,7 @@ describe('useMutation', () => {
return (
<div>
{items.map((item) => (
<button key={item} onClick={() => deleteMutation.mutate(item)}>
<button key={item} onClick={() => mutate(item)}>
delete {item}
</button>
))}
Expand Down
Loading