@@ -291,26 +291,45 @@ describe('@data/use-query', () => {
291291 spy . mockClear ( ) ;
292292 } ) ;
293293
294- // test.only('xxx', async () => {
295- // const DataLoader = component(() => {
296- // const { data } = useQuery(Key.GET_DATA, ({ id }) => api.getData(id, true), {
297- // variables: { id: 2 },
298- // });
299-
300- // return <div>{data}</div>;
301- // });
302- // const App = component(() => {
303- // return (
304- // <ErrorBoundary fallback={<div>ERROR!</div>}>
305- // <DataLoader />
306- // </ErrorBoundary>
307- // );
308- // });
309- // const { renderToString } = createServerEnv();
310- // const result = await renderToString(withProvider(<App />));
311-
312- // expect(result).toMatchInlineSnapshot(
313- // `"<div>ERROR!</div><script type="text/dark-state">"eyIxIjpbbnVsbCwiRXJyb3I6IG9vcHMhIl19"</script>"`,
314- // );
315- // });
294+ test ( 'renders with error-boundary in the browser correctly' , async ( ) => {
295+ const DataLoader = component ( ( ) => {
296+ const { data } = useQuery ( Key . GET_DATA , ( ) => api . getData ( 2 , true ) ) ;
297+
298+ return < div > { data } </ div > ;
299+ } ) ;
300+ const App = component ( ( ) => {
301+ return (
302+ < ErrorBoundary fallback = { < div > ERROR!</ div > } >
303+ < DataLoader />
304+ </ ErrorBoundary >
305+ ) ;
306+ } ) ;
307+
308+ render ( withProvider ( < App /> ) ) ;
309+ await waitQuery ( ) ;
310+ expect ( host . innerHTML ) . toMatchInlineSnapshot ( `"<div>ERROR!</div>"` ) ;
311+ } ) ;
312+
313+ test ( 'renders with error-boundary on the server correctly' , async ( ) => {
314+ const DataLoader = component ( ( ) => {
315+ const { data, error } = useQuery ( Key . GET_DATA , ( ) => api . getData ( 2 , true ) ) ;
316+
317+ if ( error ) return < div > { error } </ div > ;
318+
319+ return < div > { data } </ div > ;
320+ } ) ;
321+ const App = component ( ( ) => {
322+ return (
323+ < ErrorBoundary fallback = { < div > it renders only on the client</ div > } >
324+ < DataLoader />
325+ </ ErrorBoundary >
326+ ) ;
327+ } ) ;
328+ const { renderToString } = createServerEnv ( ) ;
329+ const result = await renderToString ( withProvider ( < App /> ) ) ;
330+
331+ expect ( result ) . toMatchInlineSnapshot (
332+ `"<div>Error: oops!</div><script type="text/dark-state">"eyIxIjpbbnVsbCwiRXJyb3I6IG9vcHMhIl19"</script>"` ,
333+ ) ;
334+ } ) ;
316335} ) ;
0 commit comments