@@ -81,12 +81,15 @@ describe("counterfact", () => {
8181
8282 it ( "uses the first spec's runner as primary (contextRegistry, registry) when specs are provided" , async ( ) => {
8383 const realCreate = ApiRunner . create ;
84- const capturedRunners : ApiRunner [ ] = [ ] ;
84+ const capturedRunnersByGroup = new Map < string , ApiRunner > ( ) ;
8585
8686 const createSpy = jest . spyOn ( ApiRunner , "create" ) ;
8787 createSpy . mockImplementation ( async ( ...args ) => {
8888 const runner = await realCreate . apply ( ApiRunner , args ) ;
89- capturedRunners . push ( runner ) ;
89+ const group = args [ 1 ] ;
90+ if ( group ) {
91+ capturedRunnersByGroup . set ( group , runner ) ;
92+ }
9093 return runner ;
9194 } ) ;
9295
@@ -96,10 +99,12 @@ describe("counterfact", () => {
9699 ] ;
97100
98101 const result = await ( app as any ) . counterfact ( mockConfig , specs ) ;
102+ const firstRunner = capturedRunnersByGroup . get ( "v1" ) ;
99103
100- expect ( capturedRunners ) . toHaveLength ( 2 ) ;
101- expect ( result . contextRegistry ) . toBe ( capturedRunners [ 0 ] ! . contextRegistry ) ;
102- expect ( result . registry ) . toBe ( capturedRunners [ 0 ] ! . registry ) ;
104+ expect ( capturedRunnersByGroup . size ) . toBe ( 2 ) ;
105+ expect ( firstRunner ) . toBeDefined ( ) ;
106+ expect ( result . contextRegistry ) . toBe ( firstRunner ! . contextRegistry ) ;
107+ expect ( result . registry ) . toBe ( firstRunner ! . registry ) ;
103108
104109 createSpy . mockRestore ( ) ;
105110 } ) ;
0 commit comments