mercredi 13 janvier 2021

Angular Test Coverage - Promises

I cannot seem to get this code to have coverage show. I have this snippet:

      DeleteConfirmed() {
        this.service.call("Handller", "delete", [Number(this.loginService.session.sessionId),this.actionId]).then(
          (res:any) => {
            this.actionId = -1;
            this.Search();
          }, this.errorService.error);
      }

and the test that looks like

  it('#DeleteConfirmed should call the delete function', () => {
    const spies = spyOn(component, "Search");
    var spy = spyOn(amfService, 'call').and.returnValue(Promise.resolve({}));
    component.DeleteConfirmed();
    tick();
    fixture.detectChanges();
    expect(spy).toHaveBeenCalled();
    expect(component.actionId).toBe(-1);
    expect(spies).toHaveBeenCalled();
  });

and the coverage inside the result never shows coverage...

    (res:any) => {
        this.actionId = -1;
        this.Search();
    }

Any help is greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire