【问题标题】:PATCH call Angular service testPATCH 调用 Angular 服务测试
【发布时间】:2020-05-06 07:47:02
【问题描述】:

我有以下服务:

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(() => { }),
    )
  }

在规范中:

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`' });
  });

BuI 收到以下错误:

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

如何使用参数和正文测试此请求?

【问题讨论】:

    标签: angular testing service parameters patch


    【解决方案1】:

    之后

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

    刷一下

    req.flush({});
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-30
      • 2013-11-08
      • 2020-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多