Skip to content

Commit 80d74c3

Browse files
committed
Update react tests to properly capture some errors
1 parent 341a5cc commit 80d74c3

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

packages/react/tests/useSuspenseQuery.test.tsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,29 @@ describe('useSuspenseQuery', () => {
5656
});
5757

5858
it('should error when PowerSync is not set', async () => {
59-
expect(() => {
60-
renderHook(() => useSuspenseQuery('SELECT * from lists'));
61-
}).toThrow('PowerSync not configured.');
59+
// don't log errors to console, since an error is expected
60+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {});
61+
62+
// use a custom error wrapper that captures the content of the error
63+
const wrapper = ({ children }) => {
64+
return (
65+
<ErrorBoundary fallbackRender={({ error }) => <div data-testid="error-div">{error.message}</div>}>
66+
<React.Suspense fallback={loadingFallback}>{children}</React.Suspense>
67+
</ErrorBoundary>
68+
);
69+
};
70+
71+
renderHook(() => useSuspenseQuery('SELECT * FROM lists'), { wrapper });
72+
73+
await waitFor(
74+
() => {
75+
expect(screen.getByTestId('error-div').textContent).toBe('PowerSync not configured.');
76+
},
77+
{ timeout: 100 }
78+
);
79+
80+
// reinstate error logging
81+
spy.mockRestore();
6282
});
6383

6484
it('should suspend on initial load', async () => {

0 commit comments

Comments
 (0)