@@ -55,6 +55,7 @@ export async function render<SutType, WrapperType = SutType>(
55
55
wrapper = WrapperComponent as Type < WrapperType > ,
56
56
componentProperties = { } ,
57
57
componentProviders = [ ] ,
58
+ ɵcomponentImports : componentImports ,
58
59
excludeComponentDeclaration = false ,
59
60
routes = [ ] ,
60
61
removeAngularAttributes = false ,
@@ -83,6 +84,7 @@ export async function render<SutType, WrapperType = SutType>(
83
84
providers : [ ...providers ] ,
84
85
schemas : [ ...schemas ] ,
85
86
} ) ;
87
+ overrideComponentImports ( sut , componentImports ) ;
86
88
87
89
await TestBed . compileComponents ( ) ;
88
90
@@ -128,23 +130,23 @@ export async function render<SutType, WrapperType = SutType>(
128
130
const [ path , params ] = ( basePath + href ) . split ( '?' ) ;
129
131
const queryParams = params
130
132
? 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 [ ] > )
142
144
: undefined ;
143
145
144
146
const navigateOptions : NavigationExtras | undefined = queryParams
145
147
? {
146
- queryParams,
147
- }
148
+ queryParams,
149
+ }
148
150
: undefined ;
149
151
150
152
const doNavigate = ( ) => {
@@ -264,6 +266,18 @@ function setComponentProperties<SutType>(
264
266
return fixture ;
265
267
}
266
268
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
+
267
281
function hasOnChangesHook < SutType > ( componentInstance : SutType ) : componentInstance is SutType & OnChanges {
268
282
return (
269
283
'ngOnChanges' in componentInstance && typeof ( componentInstance as SutType & OnChanges ) . ngOnChanges === 'function'
@@ -397,7 +411,7 @@ if (typeof process === 'undefined' || !process.env?.ATL_SKIP_AUTO_CLEANUP) {
397
411
}
398
412
399
413
@Component ( { selector : 'atl-wrapper-component' , template : '' } )
400
- class WrapperComponent { }
414
+ class WrapperComponent { }
401
415
402
416
/**
403
417
* Wrap findBy queries to poke the Angular change detection cycle
0 commit comments