Skip to content

Commit c6fd4a6

Browse files
committed
Added test for confirming error on query execution.
1 parent 72beb71 commit c6fd4a6

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

packages/tanstack-react-query/tests/useQuery.test.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,36 @@ describe('useQuery', () => {
6565
}, { timeout: 500 });
6666
});
6767

68+
it('should set error during query execution', async () => {
69+
const mockPowerSyncError = {
70+
currentStatus: { status: 'initial' },
71+
registerListener: vi.fn(() => { }),
72+
onChangeWithCallback: vi.fn(),
73+
resolveTables: vi.fn(() => ['table1', 'table2']),
74+
getAll: vi.fn(() => {
75+
throw new Error('some error');
76+
})
77+
};
78+
79+
const wrapper = ({ children }) => (
80+
<QueryClientProvider client={queryClient}>
81+
<PowerSyncContext.Provider value={mockPowerSyncError as any}>{children}</PowerSyncContext.Provider>
82+
</QueryClientProvider>
83+
);
84+
85+
const { result } = renderHook(() => useQuery({
86+
queryKey: ['lists'],
87+
query: 'SELECT * from lists'
88+
}), { wrapper });
89+
90+
await waitFor(
91+
async () => {
92+
expect(result.current.error).toEqual(Error('some error'));
93+
},
94+
{ timeout: 100 }
95+
);
96+
});
97+
6898
it('should execute compatible queries', async () => {
6999
const compilableQuery = {
70100
execute: () => [{ test: 'custom' }] as any,

0 commit comments

Comments
 (0)