简体   繁体   中英

Can't get test coverage for function

I need help with getting code coverage for the following function. I'm not sure how to get into the code highlighted below

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);
  }***
);

}

Try Something like :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM