@@ -545,6 +545,95 @@ describe('Suite', function() {
545545 expect ( suite . timeout ( ) , 'to be' , 100 ) ;
546546 } ) ;
547547 } ) ;
548+
549+ describe ( 'hasOnly()' , function ( ) {
550+ it ( 'should return true if a test has `only`' , function ( ) {
551+ var suite = new Suite ( 'foo' ) ;
552+ var test = new Test ( 'bar' ) ;
553+
554+ suite . appendOnlyTest ( test ) ;
555+
556+ expect ( suite . hasOnly ( ) , 'to be' , true ) ;
557+ } ) ;
558+
559+ it ( 'should return true if a suite has `only`' , function ( ) {
560+ var suite = new Suite ( 'foo' ) ;
561+ var nested = new Suite ( 'bar' ) ;
562+
563+ suite . appendOnlySuite ( nested ) ;
564+
565+ expect ( suite . hasOnly ( ) , 'to be' , true ) ;
566+ } ) ;
567+
568+ it ( 'should return true if nested suite has `only`' , function ( ) {
569+ var suite = new Suite ( 'foo' ) ;
570+ var nested = new Suite ( 'bar' ) ;
571+ var test = new Test ( 'baz' ) ;
572+
573+ nested . appendOnlyTest ( test ) ;
574+ // `nested` has a `only` test, but `suite` doesn't know about it
575+ suite . suites . push ( nested ) ;
576+
577+ expect ( suite . hasOnly ( ) , 'to be' , true ) ;
578+ } ) ;
579+
580+ it ( 'should return false if no suite or test is marked `only`' , function ( ) {
581+ var suite = new Suite ( 'foo' ) ;
582+ var nested = new Suite ( 'bar' ) ;
583+ var test = new Test ( 'baz' ) ;
584+
585+ suite . suites . push ( nested ) ;
586+ nested . tests . push ( test ) ;
587+
588+ expect ( suite . hasOnly ( ) , 'to be' , false ) ;
589+ } ) ;
590+ } ) ;
591+
592+ describe ( '.filterOnly()' , function ( ) {
593+ it ( 'should filter out all other tests and suites if a test has `only`' , function ( ) {
594+ var suite = new Suite ( 'a' ) ;
595+ var nested = new Suite ( 'b' ) ;
596+ var test = new Test ( 'c' ) ;
597+ var test2 = new Test ( 'd' ) ;
598+
599+ suite . suites . push ( nested ) ;
600+ suite . appendOnlyTest ( test ) ;
601+ suite . tests . push ( test2 ) ;
602+
603+ suite . filterOnly ( ) ;
604+
605+ expect ( suite , 'to satisfy' , {
606+ suites : expect . it ( 'to be empty' ) ,
607+ tests : expect
608+ . it ( 'to have length' , 1 )
609+ . and ( 'to have an item satisfying' , { title : 'c' } )
610+ } ) ;
611+ } ) ;
612+
613+ it ( 'should filter out all other tests and suites if a suite has `only`' , function ( ) {
614+ var suite = new Suite ( 'a' ) ;
615+ var nested1 = new Suite ( 'b' ) ;
616+ var nested2 = new Suite ( 'c' ) ;
617+ var test = new Test ( 'd' ) ;
618+ var nestedTest = new Test ( 'e' ) ;
619+
620+ nested1 . appendOnlyTest ( nestedTest ) ;
621+
622+ suite . tests . push ( test ) ;
623+ suite . suites . push ( nested1 ) ;
624+ suite . appendOnlySuite ( nested1 ) ;
625+ suite . suites . push ( nested2 ) ;
626+
627+ suite . filterOnly ( ) ;
628+
629+ expect ( suite , 'to satisfy' , {
630+ suites : expect
631+ . it ( 'to have length' , 1 )
632+ . and ( 'to have an item satisfying' , { title : 'b' } ) ,
633+ tests : expect . it ( 'to be empty' )
634+ } ) ;
635+ } ) ;
636+ } ) ;
548637} ) ;
549638
550639describe ( 'Test' , function ( ) {
0 commit comments