@@ -492,32 +492,26 @@ describe('createPrompt()', () => {
492
492
493
493
it ( 'clear timeout when force closing' , { timeout : 1000 } , async ( ) => {
494
494
const exitSpy = vi . fn ( ) ;
495
- const prompt = createPrompt (
496
- ( config : { message : string } , done : ( value : string ) => void ) => {
497
- const timeout = useRef < NodeJS . Timeout | undefined > ( ) ;
498
- const cleaned = useRef ( false ) ;
499
- useKeypress ( ( ) => {
500
- if ( cleaned . current ) {
501
- expect . unreachable ( 'once cleaned up keypress should not be called' ) ;
502
- }
503
- clearTimeout ( timeout . current ) ;
504
- timeout . current = setTimeout ( ( ) => { } , 1000 ) ;
505
- } ) ;
506
-
507
- exitSpy . mockImplementation ( ( ) => {
508
- clearTimeout ( timeout . current ) ;
509
- cleaned . current = true ;
510
- // We call done explicitly, as onSignalExit is not triggered in this case
511
- // But, CTRL+C will trigger rl.close, which should call this effect
512
- // This way we can have the promise resolve
513
- done ( 'closed' ) ;
514
- } ) ;
515
-
516
- useEffect ( ( ) => exitSpy , [ ] ) ;
517
-
518
- return config . message ;
519
- } ,
520
- ) ;
495
+ const prompt = createPrompt ( ( config : { message : string } ) => {
496
+ const timeout = useRef < NodeJS . Timeout | undefined > ( ) ;
497
+ const cleaned = useRef ( false ) ;
498
+ useKeypress ( ( ) => {
499
+ if ( cleaned . current ) {
500
+ expect . unreachable ( 'once cleaned up keypress should not be called' ) ;
501
+ }
502
+ clearTimeout ( timeout . current ) ;
503
+ timeout . current = setTimeout ( ( ) => { } , 1000 ) ;
504
+ } ) ;
505
+
506
+ exitSpy . mockImplementation ( ( ) => {
507
+ clearTimeout ( timeout . current ) ;
508
+ cleaned . current = true ;
509
+ } ) ;
510
+
511
+ useEffect ( ( ) => exitSpy , [ ] ) ;
512
+
513
+ return config . message ;
514
+ } ) ;
521
515
522
516
const { answer, events } = await render ( prompt , { message : 'Question' } ) ;
523
517
@@ -526,7 +520,8 @@ describe('createPrompt()', () => {
526
520
// This closes the readline
527
521
events . keypress ( { ctrl : true , name : 'c' } ) ;
528
522
529
- await expect ( answer ) . resolves . toBe ( 'closed' ) ;
523
+ await expect ( answer ) . rejects . toThrow ( 'User force closed the prompt with SIGINT' ) ;
524
+
530
525
expect ( exitSpy ) . toHaveBeenCalledTimes ( 1 ) ;
531
526
} ) ;
532
527
0 commit comments