File tree Expand file tree Collapse file tree 1 file changed +23
-3
lines changed Expand file tree Collapse file tree 1 file changed +23
-3
lines changed Original file line number Diff line number Diff 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 ( ) => {
You can’t perform that action at this time.
0 commit comments