Guest User

Untitled

a guest
Jan 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. function getMyComponent(hostFixture: ComponentFixture<any>): MyComponent {
  2. const debugElement = hostFixture.debugElement.query(By.directive(MyComponent));
  3.  
  4. return (debugElement && debugElement.componentInstance) || null;
  5. }
  6.  
  7. const instance: MyComponent = getDirective<MyComponent>(fixture);
  8.  
  9. function getDirective<T>(hostFixture: ComponentFixture<any>): T {
  10. const debugElement = hostFixture.debugElement.query(By.directive(T));
  11.  
  12. return (debugElement && debugElement.componentInstance) || null;
  13. }
  14.  
  15. function getDirective<T>(
  16. hostFixture: ComponentFixture<any>,
  17. directive: new (...args: any[]) => T
  18. ): T {
  19. const debugElement =
  20. hostFixture.debugElement.query(By.directive(directive));
  21.  
  22. return (debugElement && debugElement.componentInstance) || undefined;
  23. }
Add Comment
Please, Sign In to add comment