File tree 2 files changed +43
-4
lines changed
2 files changed +43
-4
lines changed Original file line number Diff line number Diff line change @@ -295,6 +295,7 @@ function createSuiteCollector(
295
295
mode : RunMode ,
296
296
each ?: boolean ,
297
297
suiteOptions ?: TestOptions ,
298
+ parentCollectorFixtures ?: FixtureItem [ ] ,
298
299
) {
299
300
const tasks : ( Test | Suite | SuiteCollector ) [ ] = [ ]
300
301
@@ -395,7 +396,7 @@ function createSuiteCollector(
395
396
test . type = 'test'
396
397
} )
397
398
398
- let collectorFixtures : FixtureItem [ ] | undefined
399
+ let collectorFixtures = parentCollectorFixtures
399
400
400
401
const collector : SuiteCollector = {
401
402
type : 'collector' ,
@@ -555,6 +556,7 @@ function createSuite() {
555
556
mode ,
556
557
this . each ,
557
558
options ,
559
+ currentSuite ?. fixtures ( ) ,
558
560
)
559
561
}
560
562
@@ -768,14 +770,15 @@ export function createTaskCollector(
768
770
) {
769
771
const collector = getCurrentSuite ( )
770
772
const scopedFixtures = collector . fixtures ( )
773
+ const context = { ...this }
771
774
if ( scopedFixtures ) {
772
- this . fixtures = mergeScopedFixtures (
773
- this . fixtures || [ ] ,
775
+ context . fixtures = mergeScopedFixtures (
776
+ context . fixtures || [ ] ,
774
777
scopedFixtures ,
775
778
)
776
779
}
777
780
collector . test . fn . call (
778
- this ,
781
+ context ,
779
782
formatName ( name ) ,
780
783
optionsOrFn as TestOptions ,
781
784
optionsOrTest as TestFunction ,
Original file line number Diff line number Diff line change @@ -451,3 +451,39 @@ describe('scoping variables to suite', () => {
451
451
} )
452
452
} )
453
453
} )
454
+
455
+ describe ( 'test.scoped repro #7793' , ( ) => {
456
+ const extendedTest = test . extend < { foo : boolean } > ( {
457
+ foo : false ,
458
+ } )
459
+
460
+ describe ( 'top level' , ( ) => {
461
+ extendedTest . scoped ( { foo : true } )
462
+
463
+ describe ( 'second level' , ( ) => {
464
+ extendedTest ( 'foo is true' , ( { foo } ) => {
465
+ expect ( foo ) . toBe ( true )
466
+ } )
467
+ } )
468
+ } )
469
+ } )
470
+
471
+ describe ( 'test.scoped repro #7813' , ( ) => {
472
+ const extendedTest = test . extend < { foo ?: boolean } > ( {
473
+ foo : false ,
474
+ } )
475
+
476
+ describe ( 'foo is scoped to true' , ( ) => {
477
+ extendedTest . scoped ( { foo : true } )
478
+
479
+ extendedTest ( 'foo is true' , ( { foo } ) => {
480
+ expect ( foo ) . toBe ( true )
481
+ } )
482
+ } )
483
+
484
+ describe ( 'foo is left as default of false' , ( ) => {
485
+ extendedTest ( 'foo is false' , ( { foo } ) => {
486
+ expect ( foo ) . toBe ( false )
487
+ } )
488
+ } )
489
+ } )
You can’t perform that action at this time.
0 commit comments