lundi 19 novembre 2018

Angular 6 Unit Testing Dependant Promises

I am new to Angular and I am currently writing unit tests for my application. I am really puzzled and can't seem to get any furthur with writing Unit Tests for my current task. My component makes use of the following method:

async updateLevelModes(level: Level) {
    const updateModes: Promise<any>[] = [];
    for(let mode of level.Modes) {
      const updateMode = this.modeService.updateMode(mode);
      updateModes.push(updateMode);
    }
    await Promise.all(updateModes);
    const update = await this.LevelService.updateLevel(level);
    level.Id = update._id;
  }

It makes use of two services, the modeService and the levelService.

My LevelService.ts looks like this

async updateLevel(level: Level): Promise<void> {
    const formdata = new FormData();
    formdata.append('Name', level.Name);
    formdata.append('Description', level.Description);
    formdata.append('ImageFile', level.ImageFile);

    const resultLevel = await this.http.put<IStep>(this.postStepsUrl+'/'+step.Id, formdata)
      .pipe(catchError(this.errorHandler))
      .toPromise<IStep>();
    this.HandleStepResult(Level, resultLevel);
  }

How should I write a test for such a complicated method ? Kindly help

Aucun commentaire:

Enregistrer un commentaire