Skip to content

Commit

Permalink
fix: detectchanges on type component
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Jun 16, 2018
1 parent d9f292c commit 306a453
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions projects/ngx-testing-library/src/lib/ngx-testing-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export async function createComponent<T>(
{ detectChanges = true, declarations = [], providers = [], imports = [], schemas = [] }: Options,
): Promise<Result> {
const isTemplate = typeof templateOrComponent === 'string';
const extraDeclarations = isTemplate ? [TestComponent] : [];
const testComponent = isTemplate ? [TestComponent] : [];

TestBed.configureTestingModule({
declarations: [...declarations, ...extraDeclarations],
declarations: [...declarations, ...testComponent],
providers: [...providers],
imports: [...imports],
schemas: [...schemas],
Expand All @@ -37,9 +37,6 @@ export async function createComponent<T>(
let fixture;
if (isTemplate) {
fixture = TestBed.createComponent(TestComponent);
if (detectChanges) {
fixture.detectChanges();
}
} else {
const { component, parameters = [] } = <ComponentInput<T>>templateOrComponent;
fixture = TestBed.createComponent(component);
Expand All @@ -48,6 +45,10 @@ export async function createComponent<T>(
}
}

if (detectChanges) {
fixture.detectChanges();
}

// Currently this isn't perfect because the typings from dom-testing-library are for TS 2.8
return {
fixture,
Expand Down

0 comments on commit 306a453

Please sign in to comment.