Skip to content

Commit 306a453

Browse files
committed
fix: detectchanges on type component
1 parent d9f292c commit 306a453

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ export async function createComponent<T>(
1515
{ detectChanges = true, declarations = [], providers = [], imports = [], schemas = [] }: Options,
1616
): Promise<Result> {
1717
const isTemplate = typeof templateOrComponent === 'string';
18-
const extraDeclarations = isTemplate ? [TestComponent] : [];
18+
const testComponent = isTemplate ? [TestComponent] : [];
1919

2020
TestBed.configureTestingModule({
21-
declarations: [...declarations, ...extraDeclarations],
21+
declarations: [...declarations, ...testComponent],
2222
providers: [...providers],
2323
imports: [...imports],
2424
schemas: [...schemas],
@@ -37,9 +37,6 @@ export async function createComponent<T>(
3737
let fixture;
3838
if (isTemplate) {
3939
fixture = TestBed.createComponent(TestComponent);
40-
if (detectChanges) {
41-
fixture.detectChanges();
42-
}
4340
} else {
4441
const { component, parameters = [] } = <ComponentInput<T>>templateOrComponent;
4542
fixture = TestBed.createComponent(component);
@@ -48,6 +45,10 @@ export async function createComponent<T>(
4845
}
4946
}
5047

48+
if (detectChanges) {
49+
fixture.detectChanges();
50+
}
51+
5152
// Currently this isn't perfect because the typings from dom-testing-library are for TS 2.8
5253
return {
5354
fixture,

0 commit comments

Comments
 (0)