99import { setTimeout } from 'node:timers/promises' ;
1010import { promiseWithAbort } from '../../src/utils/promise' ;
1111
12+ function expectRejectedWithError ( promise : Promise < any > ) {
13+ if ( typeof expectAsync === 'function' ) {
14+ return expectAsync ( promise ) . toBeRejectedWithError ( ) ;
15+ } else {
16+ // @ts -expect-error
17+ return expect ( promise ) . rejects . toThrowError ( ) ;
18+ }
19+ }
20+
21+ function expectResolved ( promise : Promise < any > ) {
22+ if ( typeof expectAsync === 'function' ) {
23+ return expectAsync ( promise ) . toBeResolved ( ) ;
24+ } else {
25+ // @ts -expect-error
26+ return expect ( promise ) . resolves ;
27+ }
28+ }
29+
1230describe ( 'promiseWithAbort' , ( ) => {
1331 it ( 'should reject with an AbortError when the signal is aborted' , async ( ) => {
1432 const abortController = new AbortController ( ) ;
1533 const promise = promiseWithAbort ( setTimeout ( 500 ) , abortController . signal , 'Test operation' ) ;
1634
35+ console . error ( 'queueMicrotask to abort the signal' ) ;
1736 queueMicrotask ( ( ) => {
1837 abortController . abort ( 'Test reason' ) ;
1938 } ) ;
2039
21- await expectAsync ( promise ) . toBeRejectedWithError ( ) ;
40+ console . error ( 'expectAsync to be rejected with AbortError' ) ;
41+ await expectRejectedWithError ( promise ) ;
2242 } ) ;
2343
2444 it ( 'should not reject if the signal is not aborted' , async ( ) => {
@@ -31,6 +51,6 @@ describe('promiseWithAbort', () => {
3151 // Wait briefly to ensure no rejection occurs
3252 await setTimeout ( 20 ) ;
3353
34- await expectAsync ( promise ) . toBeResolved ( ) ;
54+ await expectResolved ( promise ) ;
3555 } ) ;
3656} ) ;
0 commit comments