This repository was archived by the owner on Aug 3, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -107,9 +107,11 @@ export class Fetch extends React.Component {
107107 // configured, then we need to "cancel" the previous one.
108108 cancelExistingRequest = reason => {
109109 if ( this . state . fetching && ! this . hasHandledNetworkResponse ) {
110+ const abortError = new Error ( reason ) ;
111+ abortError . name = 'AbortError' ;
110112 this . onResponseReceived ( {
111113 ...this . responseReceivedInfo ,
112- error : new Error ( reason ) ,
114+ error : abortError ,
113115 hittingNetwork : true
114116 } ) ;
115117 }
Original file line number Diff line number Diff line change @@ -982,7 +982,7 @@ describe('request cancellation', () => {
982982 } ) ;
983983
984984 test ( 'it should cancel when a double request is initiated via `doFetch`' , ( ) => {
985- expect . assertions ( 2 ) ;
985+ expect . assertions ( 3 ) ;
986986 jest . useFakeTimers ( ) ;
987987 const afterFetchMock = jest . fn ( ) ;
988988
@@ -1006,6 +1006,10 @@ describe('request cancellation', () => {
10061006 'error.message' ,
10071007 'New fetch initiated'
10081008 ) ;
1009+ expect ( afterFetchMock . mock . calls [ 0 ] [ 0 ] ) . toHaveProperty (
1010+ 'error.name' ,
1011+ 'AbortError'
1012+ ) ;
10091013 } ) ;
10101014
10111015 test ( 'it should cancel when a double request is initiated via prop changes' , ( ) => {
@@ -1026,6 +1030,10 @@ describe('request cancellation', () => {
10261030 'error.message' ,
10271031 'New fetch initiated'
10281032 ) ;
1033+ expect ( afterFetchMock . mock . calls [ 0 ] [ 0 ] ) . toHaveProperty (
1034+ 'error.name' ,
1035+ 'AbortError'
1036+ ) ;
10291037 } ) ;
10301038
10311039 test ( 'it should cancel when the component unmounts' , ( ) => {
@@ -1042,6 +1050,10 @@ describe('request cancellation', () => {
10421050 'error.message' ,
10431051 'Component unmounted'
10441052 ) ;
1053+ expect ( afterFetchMock . mock . calls [ 0 ] [ 0 ] ) . toHaveProperty (
1054+ 'error.name' ,
1055+ 'AbortError'
1056+ ) ;
10451057 expect ( afterFetchMock ) . toBeCalledWith (
10461058 expect . objectContaining ( {
10471059 url : '/test/hangs' ,
You can’t perform that action at this time.
0 commit comments