无法获得功能的测试范围

时间:2018-10-22 06:10:05

标签: angular unit-testing karma-jasmine

我需要以下代码的代码覆盖率的帮助。我不确定如何进入下面突出显示的代码

enter image description here

 submitContactForm(): void {
 const contactData: ContactData = {
  'name': this.name.value,
  'email': this.email.value,
  'subject': this.subject.value,
  'description': this.description.value,
  'userId': null,
  'siteSource': this.authService.getSiteSource()
};

***this.xyzService.submitQuery(contactData).subscribe(
  resp => {
    console.log('Contact Us got a positive response');
    console.log(resp);
    this.alertService.success('Success', 'Your message has been sent successfully. We will reply to you as soon as possible');
  },
  err => {
    this.alertService.showAlert(err);
    console.log('Contact Us got a ERROR response');
    console.log(err);
  }***
);

}

1 个答案:

答案 0 :(得分:0)

尝试类似的东西:

  component.submitContactForm()   
  fixture.detectChanges();
    fixture.whenStable().then(() => {
      fixture.detectChanges();
      expect(result).toEqual(desiredValue);
   });