From b2a71e7b2b929f25379dc2fb51d2c3abdbf0f346 Mon Sep 17 00:00:00 2001 From: Arundathi Patil Date: Mon, 30 Jul 2018 15:45:23 +0530 Subject: Fixed error in user-login-form spec file Test cases in userLogin-form spec file failed with below error, Error: Cannot read property 'root' of undefined. This error was because, activated route was not injected into the testingbed. Fixed this error. Issue-ID: APPC-1064 Change-Id: Ib9978b73be744204e8dd64b97abbc0959a4e5839 Signed-off-by: Arundathi Patil --- .../userlogin-form/userlogin-form.component.spec.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/app/vnfs/userlogin-form/userlogin-form.component.spec.ts b/src/app/vnfs/userlogin-form/userlogin-form.component.spec.ts index d253cb7..16863a4 100644 --- a/src/app/vnfs/userlogin-form/userlogin-form.component.spec.ts +++ b/src/app/vnfs/userlogin-form/userlogin-form.component.spec.ts @@ -2,6 +2,8 @@ ============LICENSE_START========================================== =================================================================== Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + +Modification Copyright (C) 2018 IBM =================================================================== Unless otherwise specified, all software contained herein is licensed @@ -24,6 +26,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. /* tslint:disable:no-unused-variable */ import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing'; import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; import { userloginFormComponent } from './userlogin-form.component'; import { FormsModule } from '@angular/forms'; import { NotificationService } from './../../shared/services/notification.service'; @@ -39,15 +42,21 @@ import {NotificationsService} from 'angular2-notifications'; describe('userloginFormComponent', () => { let component: userloginFormComponent; let fixture: ComponentFixture; + let mockActiveRoute = { + snapshot: { + queryParams: { + returnUrl: '/home', + } + } + }; beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [userloginFormComponent], schemas: [NO_ERRORS_SCHEMA], imports: [FormsModule, RouterTestingModule,], - providers: [UtilityService, ParamShareService, DialogService, NotificationService,NotificationsService, HttpUtilService, MappingEditorService, { - provide: Router, - useClass: MockRouter - }, { provide: Router, useClass: MockRouter }] + providers: [UtilityService, ParamShareService, DialogService,NotificationsService, HttpUtilService, MappingEditorService, + {provide: ActivatedRoute, useValue: mockActiveRoute}, + { provide: Router, useClass: MockRouter }] }) .compileComponents(); })); @@ -82,7 +91,7 @@ describe('userloginFormComponent', () => { }); it('should route to myvnfform', inject([Router], (router: Router) => { - const spy = spyOn(router, 'navigate'); + const spy = spyOn(router, 'navigateByUrl'); component.getData(); const url = spy.calls.first().args[0]; -- cgit 1.2.3-korg