import { Component } from '@angular/core' ; import { TestBed , ComponentFixture , fakeAsync , inject } from '@angular/core/testing' ; import { advance , createRoot } from '../test.mocks' ; import { ScrollSpyModule } from '../module' ; import { ScrollSpyService } from './service' ; describe ( 'core window.directive' , ( ) => { var fixture ; var EventSpy ; beforeEach ( ( ) => { TestBed . configureTestingModule ( { imports : [ ScrollSpyModule . forRoot ( ) ] , declarations : [ RootCmp ] } ) ; EventSpy = jasmine . createSpy ( 'EventSpy' ) ; } ) ; afterEach ( ( ) => { TestBed . resetTestingModule ( ) ; } ) ; it ( 'should subscribe to window scroll events' , fakeAsync ( inject ( [ ScrollSpyService ] , ( scrollSpyService ) => { fixture = createRoot ( RootCmp ) ; expect ( EventSpy ) . not . toHaveBeenCalled ( ) ; scrollSpyService . getObservable ( 'window' ) . subscribe ( ( e ) => EventSpy ( e ) ) ; advance ( fixture ) ; var evt = document . createEvent ( 'UIEvents' ) ; evt . initUIEvent ( 'scroll' , true , true , window , 1 ) ; window . dispatchEvent ( evt ) ; advance ( fixture ) ; expect ( EventSpy ) . toHaveBeenCalledWith ( evt ) ; } ) ) ) ; } ) ; @ Component ( { selector : 'root-comp' , template : `<div scrollSpy></div>` } ) class RootCmp { }