Guest User

Untitled

a guest
Jul 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. <div class="child" (click)="testClick($event)"></div>
  2.  
  3. testClick(event) {
  4. console.log(event);
  5. }
  6.  
  7. describe('AppComponent', () => {
  8. let fixture: ComponentFixture<AppComponent>;
  9. let app: AppComponent;
  10. let child: DebugElement;
  11.  
  12. beforeEach(async(() => {
  13. TestBed.configureTestingModule({
  14. imports: [ ChildModule ],
  15. declarations: [
  16. AppComponent
  17. ],
  18. }).compileComponents();
  19. }));
  20. beforeEach(() => {
  21. fixture = TestBed.createComponent(AppComponent);
  22. app = fixture.debugElement.componentInstance;
  23. child = fixture.debugElement.query(By.css('.child'));
  24. fixture.detectChanges();
  25. });
  26.  
  27. it(`should create the handle of the joystick'`, async(() => {
  28. expect(child).toBeTruthy();
  29. }));
  30.  
  31. it(`clicks on the joystick handle and the relative Observable emits`, async(() => {
  32. setTimeout(() => {
  33. childHandle.triggerEventHandler('click', 'clicked');
  34. }, 100);
  35.  
  36. }));
  37.  
  38. });
  39.  
  40. export class ChildComponent implements AfterViewInit {
  41. @ViewChild('child') private childElement: ElementRef;
  42.  
  43. ngAfterViewInit() {
  44. const testClick$ = fromEvent(this.childElement.nativeElement, 'click');
  45. testClick$.subscribe(d => console.log('test click in child', d));
  46. }
  47. }
Add Comment
Please, Sign In to add comment