Skip to content

Commit

Permalink
Added test for confirming error on query execution.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chriztiaan committed Nov 27, 2024
1 parent 72beb71 commit 192705c
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/tanstack-react-query/tests/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,37 @@ describe('useQuery', () => {
}, { timeout: 500 });
});

it('should set error during query execution', async () => {
const mockPowerSyncError = {
currentStatus: { status: 'initial' },
registerListener: vi.fn(() => { }),
onChangeWithCallback: vi.fn(),
resolveTables: vi.fn(() => ['table1', 'table2']),
getAll: vi.fn(() => {
throw new Error('some error');
})
};

const wrapper = ({ children }) => (
<QueryClientProvider client={queryClient}>
<PowerSyncContext.Provider value={mockPowerSyncError as any}>{children}</PowerSyncContext.Provider>
</QueryClientProvider>
);

const { result } = renderHook(() => useQuery({
queryKey: ['lists'],
query: 'SELECT * from lists'
}), { wrapper });

await waitFor(
async () => {
expect(result.current.error).toEqual(Error('some error'));
},
{ timeout: 100 }
);
});


it('should execute compatible queries', async () => {
const compilableQuery = {
execute: () => [{ test: 'custom' }] as any,
Expand Down

0 comments on commit 192705c

Please sign in to comment.