@@ -247,7 +247,7 @@ function parseArguments<T extends (...args: any[]) => any>(
247247 optionsOrTest : object | T | number | undefined ,
248248) {
249249 let options : TestOptions = { }
250- let fn : T = ( ( ) => { } ) as T
250+ let fn : T | undefined
251251
252252 // it('', () => {}, { retry: 2 })
253253 if ( typeof optionsOrTest === 'object' ) {
@@ -329,6 +329,9 @@ function createSuiteCollector(
329329 annotations : [ ] ,
330330 }
331331 const handler = options . handler
332+ if ( task . mode === 'run' && ! handler ) {
333+ task . mode = 'todo'
334+ }
332335 if (
333336 options . concurrent
334337 || ( ! options . sequential && runner . config . sequence . concurrent )
@@ -533,7 +536,7 @@ function createSuite() {
533536 factoryOrOptions ?: SuiteFactory | TestOptions ,
534537 optionsOrFactory ?: number | TestOptions | SuiteFactory ,
535538 ) {
536- const mode : RunMode = this . only
539+ let mode : RunMode = this . only
537540 ? 'only'
538541 : this . skip
539542 ? 'skip'
@@ -547,6 +550,10 @@ function createSuite() {
547550 optionsOrFactory ,
548551 )
549552
553+ if ( mode === 'run' && ! factory ) {
554+ mode = 'todo'
555+ }
556+
550557 const isConcurrentSpecified = options . concurrent || this . concurrent || options . sequential === false
551558 const isSequentialSpecified = options . sequential || this . sequential || options . concurrent === false
552559
@@ -606,20 +613,20 @@ function createSuite() {
606613 if ( arrayOnlyCases ) {
607614 suite (
608615 formatTitle ( _name , items , idx ) ,
609- ( ) => handler ( ...items ) ,
616+ handler ? ( ) => handler ( ...items ) : undefined ,
610617 options ,
611618 )
612619 }
613620 else {
614- suite ( formatTitle ( _name , items , idx ) , ( ) => handler ( i ) , options )
621+ suite ( formatTitle ( _name , items , idx ) , handler ? ( ) => handler ( i ) : undefined , options )
615622 }
616623 }
617624 else {
618625 if ( arrayOnlyCases ) {
619- suite ( formatTitle ( _name , items , idx ) , options , ( ) => handler ( ...items ) )
626+ suite ( formatTitle ( _name , items , idx ) , options , handler ? ( ) => handler ( ...items ) : undefined )
620627 }
621628 else {
622- suite ( formatTitle ( _name , items , idx ) , options , ( ) => handler ( i ) )
629+ suite ( formatTitle ( _name , items , idx ) , options , handler ? ( ) => handler ( i ) : undefined )
623630 }
624631 }
625632 } )
@@ -648,7 +655,7 @@ function createSuite() {
648655 const name_ = formatName ( name )
649656 const { options, handler } = parseArguments ( optionsOrFn , fnOrOptions )
650657 cases . forEach ( ( item , idx ) => {
651- suite ( formatTitle ( name_ , toArray ( item ) , idx ) , options , ( ) => handler ( item ) )
658+ suite ( formatTitle ( name_ , toArray ( item ) , idx ) , options , handler ? ( ) => handler ( item ) : undefined )
652659 } )
653660 }
654661 }
@@ -704,20 +711,20 @@ export function createTaskCollector(
704711 if ( arrayOnlyCases ) {
705712 test (
706713 formatTitle ( _name , items , idx ) ,
707- ( ) => handler ( ...items ) ,
714+ handler ? ( ) => handler ( ...items ) : undefined ,
708715 options ,
709716 )
710717 }
711718 else {
712- test ( formatTitle ( _name , items , idx ) , ( ) => handler ( i ) , options )
719+ test ( formatTitle ( _name , items , idx ) , handler ? ( ) => handler ( i ) : undefined , options )
713720 }
714721 }
715722 else {
716723 if ( arrayOnlyCases ) {
717- test ( formatTitle ( _name , items , idx ) , options , ( ) => handler ( ...items ) )
724+ test ( formatTitle ( _name , items , idx ) , options , handler ? ( ) => handler ( ...items ) : undefined )
718725 }
719726 else {
720- test ( formatTitle ( _name , items , idx ) , options , ( ) => handler ( i ) )
727+ test ( formatTitle ( _name , items , idx ) , options , handler ? ( ) => handler ( i ) : undefined )
721728 }
722729 }
723730 } )
@@ -749,9 +756,11 @@ export function createTaskCollector(
749756 const { options, handler } = parseArguments ( optionsOrFn , fnOrOptions )
750757 cases . forEach ( ( item , idx ) => {
751758 // monkey-patch handler to allow parsing fixture
752- const handlerWrapper = ( ctx : any ) => handler ( item , ctx ) ;
753- ( handlerWrapper as any ) . __VITEST_FIXTURE_INDEX__ = 1 ;
754- ( handlerWrapper as any ) . toString = ( ) => handler . toString ( )
759+ const handlerWrapper = handler ? ( ctx : any ) => handler ( item , ctx ) : undefined
760+ if ( handlerWrapper ) {
761+ ( handlerWrapper as any ) . __VITEST_FIXTURE_INDEX__ = 1 ;
762+ ( handlerWrapper as any ) . toString = ( ) => handler ! . toString ( )
763+ }
755764 test ( formatTitle ( _name , toArray ( item ) , idx ) , options , handlerWrapper )
756765 } )
757766 }
0 commit comments