diff --git a/packages/postgrest-swr/tests/mutate/use-update-mutation.integration.spec.tsx b/packages/postgrest-swr/tests/mutate/use-update-mutation.integration.spec.tsx index 8f0ecadd9..0f61d6c66 100644 --- a/packages/postgrest-swr/tests/mutate/use-update-mutation.integration.spec.tsx +++ b/packages/postgrest-swr/tests/mutate/use-update-mutation.integration.spec.tsx @@ -99,6 +99,67 @@ describe('useUpdateMutation', () => { await screen.findByText('success: true', {}, { timeout: 10000 }); }); + it('should return an error', async () => { + const USERNAME_1 = `${testRunPrefix}-2`; + const USERNAME_2 = `${testRunPrefix}-3`; + function Page() { + const { data, count } = useQuery( + client + .from('contact') + .select('id,username', { count: 'exact' }) + .in('username', [USERNAME_1, USERNAME_2]), + { + revalidateOnFocus: false, + revalidateOnReconnect: false, + }, + ); + const { trigger: insert } = useInsertMutation(client.from('contact'), [ + 'id', + ]); + const { trigger: update, error } = useUpdateMutation( + client.from('contact'), + ['id'], + 'idonotexist', + ); + return ( +
+
await insert([{ username: USERNAME_1 }])} + /> +
+ await update({ + id: (data ?? []).find((d) => d.username === USERNAME_1)?.id, + username: USERNAME_2, + }) + } + /> + + { + data?.find((d) => + [USERNAME_1, USERNAME_2].includes(d.username ?? ''), + )?.username + } + + {`count: ${count}`} + {`error: ${!!error}`} +
+ ); + } + + renderWithConfig(, { provider: () => provider }); + await screen.findByText('count: 0', {}, { timeout: 10000 }); + + fireEvent.click(screen.getByTestId('insert')); + await screen.findByText(USERNAME_1, {}, { timeout: 10000 }); + expect(screen.getByTestId('count').textContent).toEqual('count: 1'); + + fireEvent.click(screen.getByTestId('update')); + await screen.findByText('error: true', {}, { timeout: 10000 }); + }); + it('should update existing cache item', async () => { const USERNAME_1 = `${testRunPrefix}-2`; const USERNAME_2 = `${testRunPrefix}-3`;