Created
May 23, 2019 21:55
-
-
Save krishna-acondy/0fee9763c255383366e21b9b9940b99d to your computer and use it in GitHub Desktop.
Angular Unit Testing - Test Harness
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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