Вызов PATCH Angular сервисный тест - PullRequest
0 голосов
/ 06 мая 2020

У меня есть следующая служба:

creerPass(mail: string, person: string, password: string): Observable<void> {
    const params = new HttpParams()
      .set('person', person)
      .set('mail', mail);
    return this.http.patch(`/api/user/pwd`, { password: password}, { params: params }).pipe(
      map(() => { }),
    )
  }

в SPE c .ts:

fit('should PATCH', () => {
    const person = "joe";
    const mail = "monemail@test.fr"
    const password = "fezioOkf"

    passwordService.creerPass(mail, person, password).subscribe(() => { }, fail);
    const req = http.expectOne('/api/user/pwd');
    expect(req.request.method).toEqual('PATCH');

    // http.expectOne({ method: 'PATCH', url: '/api/user/pwd?person=joe&mail=monemail@test.fr`' });
  });

Но я получаю следующую ошибку:

Error: Expected one matching request for criteria "Match URL: api/user/pwd", found none.

Как я могу проверить этот запрос с параметрами и телом?

1 Ответ

0 голосов
/ 06 мая 2020

после

const req = http.expectOne('/api/user/pwd');

грипп sh it

req.flush({});

https://angular.io/api/common/http/testing/TestRequest#flush

...