lundi 29 juin 2020

check of unit test to service in angular

I have this code:

public getProjects() {
    this.listProjects.getProjects(this.tenant).subscribe((res: any) => {
      this.eventService.get(EventKeys.ProjectSelected).subscribe((dataFilter: any) => {
        const results = _.filter(res, item => {
          const active = item.projectStatus2020 === dataFilter[0];
          const inactive = item.projectStatus2020 === dataFilter[1];
          const terminated = item.projectStatus2020 === dataFilter[2];
          return active || inactive || terminated;
        });
        const check = _.isEmpty(results);
        Iif (check === false) {
          this.items = results;
        } else {
          this.items = res;
        }
      });
    });
  }

I use this code in unit tests:

beforeEach(async(() => {
    projectServiceSpy = jasmine.createSpyObj('ProjectsService', ['getProjects']);
    projectServiceSpy.getProjects.and.returnValue(of({}));

And I don't know How to make it to check this section.

enter image description here

Someone idea?

Aucun commentaire:

Enregistrer un commentaire