Skip to content

Instantly share code, notes, and snippets.

@krishna-acondy
Created May 23, 2019 21:55
Show Gist options
  • Save krishna-acondy/0fee9763c255383366e21b9b9940b99d to your computer and use it in GitHub Desktop.
Save krishna-acondy/0fee9763c255383366e21b9b9940b99d to your computer and use it in GitHub Desktop.
Angular Unit Testing - Test Harness
export class TestHarness<T> {
constructor(public component: T, public fixture: ComponentFixture<Component>) { }
get hasComponentCreated() {
return !!this.component;
}
detectChanges() {
this.fixture.detectChanges();
}
}
export function createTestHarness<T>(componentType: Type<T>): TestHarness<T> {
let component: T;
let fixture: ComponentFixture<T>;
fixture = TestBed.createComponent<T>(componentType);
component = fixture.componentInstance;
fixture.detectChanges();
return new TestHarness<T>(component, fixture);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment