@@ -681,8 +681,7 @@ describe("API", () => {
681681 const attempt = ( ) => Promise . resolve ( [ ] ) ;
682682
683683 const retryOrTimeoutPromise = retryOrTimeout ( attempt , 1000 ) ;
684- // eslint-disable-next-line @typescript-eslint/no-floating-promises
685- vi . advanceTimersByTimeAsync ( 2000 ) ;
684+ await vi . advanceTimersByTimeAsync ( 2000 ) ;
686685
687686 const result = await retryOrTimeoutPromise ;
688687 if ( result . success ) {
@@ -701,8 +700,7 @@ describe("API", () => {
701700 . mockResolvedValueOnce ( [ ] ) ;
702701
703702 const retryOrDiePromise = retryOrTimeout ( attempt , 5000 ) ;
704- // eslint-disable-next-line @typescript-eslint/no-floating-promises
705- vi . advanceTimersByTimeAsync ( 3000 ) ;
703+ await vi . advanceTimersByTimeAsync ( 3000 ) ;
706704
707705 const result = await retryOrDiePromise ;
708706 if ( ! result . success ) {
@@ -713,5 +711,25 @@ describe("API", () => {
713711 expect ( result . value ) . toStrictEqual ( attemptResult ) ;
714712 expect ( attempt ) . toHaveBeenCalledTimes ( 3 ) ;
715713 } ) ;
714+
715+ it ( "should iterate only once if timed out" , async ( ) => {
716+ const attempt = vi . fn ( ( ) => Promise . resolve ( [ ] ) ) ;
717+
718+ const retryOrTimeoutPromise = retryOrTimeout ( attempt , 1000 ) ;
719+
720+ expect ( attempt ) . toHaveBeenCalledOnce ( ) ;
721+
722+ await vi . advanceTimersByTimeAsync ( 2000 ) ;
723+
724+ const result = await retryOrTimeoutPromise ;
725+
726+ if ( result . success ) {
727+ expect . fail ( "expected retryOrTimeout to timeout" ) ;
728+ }
729+ expect ( attempt ) . toHaveBeenCalledOnce ( ) ;
730+
731+ expect ( result . success ) . toStrictEqual ( false ) ;
732+ expect ( result . reason ) . toStrictEqual ( "timeout" ) ;
733+ } ) ;
716734 } ) ;
717735} ) ;
0 commit comments