@@ -681,8 +681,7 @@ describe("API", () => {
681
681
const attempt = ( ) => Promise . resolve ( [ ] ) ;
682
682
683
683
const retryOrTimeoutPromise = retryOrTimeout ( attempt , 1000 ) ;
684
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
685
- vi . advanceTimersByTimeAsync ( 2000 ) ;
684
+ await vi . advanceTimersByTimeAsync ( 2000 ) ;
686
685
687
686
const result = await retryOrTimeoutPromise ;
688
687
if ( result . success ) {
@@ -701,8 +700,7 @@ describe("API", () => {
701
700
. mockResolvedValueOnce ( [ ] ) ;
702
701
703
702
const retryOrDiePromise = retryOrTimeout ( attempt , 5000 ) ;
704
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
705
- vi . advanceTimersByTimeAsync ( 3000 ) ;
703
+ await vi . advanceTimersByTimeAsync ( 3000 ) ;
706
704
707
705
const result = await retryOrDiePromise ;
708
706
if ( ! result . success ) {
@@ -713,5 +711,25 @@ describe("API", () => {
713
711
expect ( result . value ) . toStrictEqual ( attemptResult ) ;
714
712
expect ( attempt ) . toHaveBeenCalledTimes ( 3 ) ;
715
713
} ) ;
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
+ } ) ;
716
734
} ) ;
717
735
} ) ;
0 commit comments