Summary Table
Categories |
Total Count |
PII |
0 |
URL |
0 |
DNS |
0 |
EKL |
0 |
IP |
0 |
PORT |
0 |
VsID |
0 |
CF |
0 |
AI |
0 |
VPD |
0 |
PL |
0 |
Other |
0 |
File Content
import { AppComponent } from './app.component';
import { WindowRefService } from './window-ref.service';
import { NavigationEnd } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
// import { Subject } from "rxjs";
describe('AppComponent', () => {
let component: AppComponent;
let windowRef: WindowRefService;
let router;
beforeEach(() => {
router = { events: () => true };
windowRef = <WindowRefService>{
nativeWindow: {
scrollTo: () => true
}
};
component = new AppComponent(router, windowRef, null);
});
it('should be created', () => {
expect(component).toBeTruthy();
});
it('test ngOnInit: "router.events" returns back a NavigationEnd object', () => {
expect(component.subscription).toEqual(undefined);
const returnedEvent = new NavigationEnd(null, null, null);
router.events = new Observable(observer => {
observer.next(returnedEvent);
observer.complete();
});
spyOn(windowRef.nativeWindow, 'scrollTo');
component.ngOnInit();
expect(component.subscription).toBeDefined();
expect(component.subscription).not.toEqual(null);
expect(windowRef.nativeWindow.scrollTo).toHaveBeenCalled();
});
it('test ngOnInit: "router.events" returns back an object that is not of type NavigationEnd', () => {
expect(component.subscription).toEqual(undefined);
const returnedEvent = {};
router.events = new Observable(observer => {
observer.next(returnedEvent);
observer.complete();
});
spyOn(windowRef.nativeWindow, 'scrollTo');
component.ngOnInit();
expect(component.subscription).toBeDefined();
expect(component.subscription).not.toEqual(null);
expect(windowRef.nativeWindow.scrollTo).not.toHaveBeenCalled();
});
it('test ngOnDestory', () => {
component.subscription = new Subscription();
spyOn(component.subscription, 'unsubscribe');
component.ngOnDestroy();
expect(component.subscription.unsubscribe).toHaveBeenCalled();
});
});