File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
packages/query-core/src/__tests__ Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -1368,6 +1368,40 @@ describe('queryObserver', () => {
13681368 unsubscribe ( )
13691369 } )
13701370
1371+ test ( 'should not track error prop when throwOnError is not set' , async ( ) => {
1372+ const key = queryKey ( )
1373+ const results : Array < QueryObserverResult > = [ ]
1374+ const observer = new QueryObserver ( queryClient , {
1375+ queryKey : key ,
1376+ queryFn : ( ) => Promise . reject ( 'error' ) ,
1377+ retry : false ,
1378+ } )
1379+
1380+ const trackedResult = observer . trackResult (
1381+ observer . getCurrentResult ( ) ,
1382+ ( prop ) => {
1383+ if ( prop === 'data' ) {
1384+ observer . trackProp ( prop )
1385+ }
1386+ } ,
1387+ )
1388+
1389+ trackedResult . data
1390+
1391+ const unsubscribe = observer . subscribe ( ( result ) => {
1392+ results . push ( result )
1393+ } )
1394+
1395+ await vi . advanceTimersByTimeAsync ( 0 )
1396+
1397+ // Without throwOnError, `error` is not auto-added to trackedProps.
1398+ // Since only `data` is tracked and it did not change (stayed undefined),
1399+ // the listener is not invoked even though `error` prop changed.
1400+ expect ( results . length ) . toBe ( 0 )
1401+
1402+ unsubscribe ( )
1403+ } )
1404+
13711405 test ( 'should reject promise when experimental_prefetchInRender is disabled and thenable is pending' , async ( ) => {
13721406 const key = queryKey ( )
13731407 const queryClient2 = new QueryClient ( {
You can’t perform that action at this time.
0 commit comments