方法内部调用的服务出错

时间:2019-04-03 14:12:24

标签: jasmine angular-testing spyon

getSiteNameByMacId(){     this.EnabledSites = [];

var macId = sessionStorage.getItem('macId');
this.dataService.getSiteNameByMacIds(macId).subscribe(data => {

  this.EnabledSites = data;

  if (this.EnabledSites.length == 1) {
    sessionStorage.setItem('siteName', this.EnabledSites[0].SiteName);
    this.route.navigate(['/type']);
  }
  if (this.EnabledSites.length == 0) {
    this.errormsg = "This PSA is not configured, please contact technical admin";
  }

});

}

it('应该调用Login Service的isUserAuthenticated方法',()=> {     const spy = spyOn(service,'getSiteNameByMacIds')。and.returnValue(Observable.empty());     component.getSiteNameByMacId();     Expect(spy).toHaveBeenCalled();   });

TypeError:无法读取未定义的属性'getSiteNameByMacIds' TypeError:无法读取未定义的属性“ getSiteNameByMacIds”     在SiteComponent.getSiteNameByMacIds [作为getSiteNameByMacId](http://localhost:9876/_karma_webpack_/webpack:/src/app/site/site.component.ts:20:26)     在SiteComponent.getSiteNameByMacId [作为ngOnInit](http://localhost:9876/_karma_webpack_/webpack:/src/app/site/site.component.ts:12:14)     在UserContext上。 (http://localhost:9876/_karma_webpack_/webpack:/src/app/site/site.component.spec.ts:87:15

0 个答案:

没有答案