Skip to content

Commit 4c61250

Browse files
committed
fix: fix config for testing with zoneless Angular
1 parent e2295c6 commit 4c61250

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

projects/testing-library/src/lib/testing-library.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,11 @@ export async function render<SutType, WrapperType = SutType>(
108108
imports: addAutoImports(sut, {
109109
imports: imports.concat(defaultImports),
110110
routes,
111+
}),
112+
providers: addAutoProviders({
113+
providers: [...providers],
111114
zoneless,
112115
}),
113-
providers: [...providers],
114116
schemas: [...schemas],
115117
deferBlockBehavior: deferBlockBehavior ?? DeferBlockBehavior.Manual,
116118
});
@@ -514,16 +516,19 @@ function addAutoDeclarations<SutType>(
514516

515517
function addAutoImports<SutType>(
516518
sut: Type<SutType> | string,
517-
{
518-
imports = [],
519-
routes,
520-
zoneless,
521-
}: Pick<RenderComponentOptions<any>, 'imports' | 'routes'> & Pick<Config, 'zoneless'>,
519+
{ imports = [], routes }: Pick<RenderComponentOptions<any>, 'imports' | 'routes'>,
522520
) {
523521
const routing = () => (routes ? [RouterTestingModule.withRoutes(routes)] : []);
524522
const components = () => (typeof sut !== 'string' && isStandalone(sut) ? [sut] : []);
523+
return [...imports, ...components(), ...routing()];
524+
}
525+
526+
function addAutoProviders({
527+
providers = [],
528+
zoneless,
529+
}: Pick<RenderTemplateOptions<any>, 'providers'> & Pick<Config, 'zoneless'>) {
525530
const provideZoneless = () => (zoneless ? [provideZonelessChangeDetection()] : []);
526-
return [...imports, ...components(), ...routing(), ...provideZoneless()];
531+
return [...providers, ...provideZoneless()];
527532
}
528533

529534
async function renderDeferBlock<SutType>(

0 commit comments

Comments
 (0)