@@ -55,6 +55,7 @@ export async function render<SutType, WrapperType = SutType>(
5555 wrapper = WrapperComponent as Type < WrapperType > ,
5656 componentProperties = { } ,
5757 componentProviders = [ ] ,
58+ ɵcomponentImports : componentImports ,
5859 excludeComponentDeclaration = false ,
5960 routes = [ ] ,
6061 removeAngularAttributes = false ,
@@ -83,6 +84,7 @@ export async function render<SutType, WrapperType = SutType>(
8384 providers : [ ...providers ] ,
8485 schemas : [ ...schemas ] ,
8586 } ) ;
87+ overrideComponentImports ( sut , componentImports ) ;
8688
8789 await TestBed . compileComponents ( ) ;
8890
@@ -128,23 +130,23 @@ export async function render<SutType, WrapperType = SutType>(
128130 const [ path , params ] = ( basePath + href ) . split ( '?' ) ;
129131 const queryParams = params
130132 ? params . split ( '&' ) . reduce ( ( qp , q ) => {
131- const [ key , value ] = q . split ( '=' ) ;
132- const currentValue = qp [ key ] ;
133- if ( typeof currentValue === 'undefined' ) {
134- qp [ key ] = value ;
135- } else if ( Array . isArray ( currentValue ) ) {
136- qp [ key ] = [ ...currentValue , value ] ;
137- } else {
138- qp [ key ] = [ currentValue , value ] ;
139- }
140- return qp ;
141- } , { } as Record < string , string | string [ ] > )
133+ const [ key , value ] = q . split ( '=' ) ;
134+ const currentValue = qp [ key ] ;
135+ if ( typeof currentValue === 'undefined' ) {
136+ qp [ key ] = value ;
137+ } else if ( Array . isArray ( currentValue ) ) {
138+ qp [ key ] = [ ...currentValue , value ] ;
139+ } else {
140+ qp [ key ] = [ currentValue , value ] ;
141+ }
142+ return qp ;
143+ } , { } as Record < string , string | string [ ] > )
142144 : undefined ;
143145
144146 const navigateOptions : NavigationExtras | undefined = queryParams
145147 ? {
146- queryParams,
147- }
148+ queryParams,
149+ }
148150 : undefined ;
149151
150152 const doNavigate = ( ) => {
@@ -264,6 +266,18 @@ function setComponentProperties<SutType>(
264266 return fixture ;
265267}
266268
269+ function overrideComponentImports < SutType > ( sut : Type < SutType > | string , imports : ( Type < any > | any [ ] ) [ ] | undefined ) {
270+ if ( imports ) {
271+ if ( typeof sut === 'function' && ɵisStandalone ( sut ) ) {
272+ TestBed . overrideComponent ( sut , { set : { imports } } ) ;
273+ } else {
274+ throw new Error (
275+ `Error while rendering ${ sut } : Cannot specify componentImports on a template or non-standalone component.` ,
276+ ) ;
277+ }
278+ }
279+ }
280+
267281function hasOnChangesHook < SutType > ( componentInstance : SutType ) : componentInstance is SutType & OnChanges {
268282 return (
269283 'ngOnChanges' in componentInstance && typeof ( componentInstance as SutType & OnChanges ) . ngOnChanges === 'function'
@@ -397,7 +411,7 @@ if (typeof process === 'undefined' || !process.env?.ATL_SKIP_AUTO_CLEANUP) {
397411}
398412
399413@Component ( { selector : 'atl-wrapper-component' , template : '' } )
400- class WrapperComponent { }
414+ class WrapperComponent { }
401415
402416/**
403417 * Wrap findBy queries to poke the Angular change detection cycle
0 commit comments