@@ -86,25 +86,40 @@ const DEFAULT_SERVICE_SINGLETON_MOCKS: [CoreSingletonProxy, unknown][] = [
8686 * @returns A promise that resolves to the testing component fixture.
8787 */
8888async function renderAngularComponent < T > ( component : Type < T > , config : RenderConfig ) : Promise < TestingComponentFixture < T > > {
89- config . declarations . push ( component ) ;
90-
91- TestBed . configureTestingModule ( {
92- declarations : [
93- ...getDefaultDeclarations ( ) ,
94- ...config . declarations ,
95- ] ,
96- providers : [
97- ...getDefaultProviders ( config ) ,
98- ...config . providers ,
99- ] ,
100- schemas : [ CUSTOM_ELEMENTS_SCHEMA ] ,
101- imports : [
102- BrowserModule ,
103- NoopAnimationsModule ,
104- TranslateModule . forChild ( ) ,
105- ...config . imports ,
106- ] ,
107- } ) ;
89+ if ( ! config . standalone ) {
90+ config . declarations . push ( component ) ;
91+
92+ TestBed . configureTestingModule ( {
93+ declarations : [
94+ ...config . declarations ,
95+ ] ,
96+ providers : [
97+ ...getDefaultProviders ( config ) ,
98+ ...config . providers ,
99+ ] ,
100+ schemas : [ CUSTOM_ELEMENTS_SCHEMA ] ,
101+ imports : [
102+ BrowserModule ,
103+ NoopAnimationsModule ,
104+ TranslateModule . forChild ( ) ,
105+ CoreExternalContentDirectiveStub ,
106+ ...config . imports ,
107+ ] ,
108+ } ) ;
109+ } else {
110+ TestBed . configureTestingModule ( {
111+ providers : [
112+ ...getDefaultProviders ( config ) ,
113+ ...config . providers ,
114+ ] ,
115+ imports : [
116+ component ,
117+ NoopAnimationsModule ,
118+ CoreExternalContentDirectiveStub ,
119+ ...config . imports ,
120+ ] ,
121+ } ) ;
122+ }
108123
109124 testBedInitialized = true ;
110125
@@ -128,7 +143,13 @@ async function renderAngularComponent<T>(component: Type<T>, config: RenderConfi
128143 * @returns The wrapper component class.
129144 */
130145function createWrapperComponent < U > ( template : string , componentClass : Type < U > ) : Type < WrapperComponent < U > > {
131- @Component ( { template } )
146+ @Component ( {
147+ template,
148+ standalone : true ,
149+ imports : [
150+ componentClass ,
151+ ] ,
152+ } )
132153 class HostComponent extends WrapperComponent < U > {
133154
134155 @ViewChild ( componentClass ) child ! : U ;
@@ -138,17 +159,6 @@ function createWrapperComponent<U>(template: string, componentClass: Type<U>): T
138159 return HostComponent ;
139160}
140161
141- /**
142- * Gets the default declarations for testing.
143- *
144- * @returns An array of default declarations.
145- */
146- function getDefaultDeclarations ( ) : unknown [ ] {
147- return [
148- CoreExternalContentDirectiveStub ,
149- ] ;
150- }
151-
152162/**
153163 * Gets the default providers for testing.
154164 *
@@ -217,6 +227,7 @@ export interface RenderConfig {
217227 providers : unknown [ ] ;
218228 imports : unknown [ ] ;
219229 translations ?: Record < string , string > ;
230+ standalone ?: boolean ;
220231}
221232
222233export interface RenderPageConfig extends RenderConfig {
@@ -447,8 +458,10 @@ export async function renderTemplate<T>(
447458 template : string ,
448459 config : Partial < RenderConfig > = { } ,
449460) : Promise < WrapperComponentFixture < T > > {
450- config . declarations = config . declarations ?? [ ] ;
451- config . declarations . push ( component ) ;
461+ if ( ! config . standalone ) {
462+ config . declarations = config . declarations ?? [ ] ;
463+ config . declarations . push ( component ) ;
464+ }
452465
453466 return renderAngularComponent (
454467 createWrapperComponent ( template , component ) ,
0 commit comments