刷新布尔类型

时间:2018-01-31 14:47:56

标签: angular typescript

我有一个测试,我无法通过或准确地发现端点。真实端点将返回truefalse作为响应。不是'true',而是布尔值true。我无法弄清楚如何.flush()布尔值:

const FLUSH_OK = {status: 200, statusText: 'Ok'};

//.. describe...
it('should work', async(() => {
  service.myFunction().subscribe((data) => { // my Function returns Observable<boolean>, the real endpoint returns a true/false boolean
    expect(data).toEqual(true);
  });

  // this fails: Failed: Automatic conversion to JSON is not supported for response type.
  httpMock.expectOne((req) => {
    return req.url === MY_URL;
  }).flush(true, FLUSH_OK);

 // this also fails: Expected 'true' to equal true.
 // httpMock.expectOne((req) => {
 //   return req.url === MY_URL;
 // }).flush('true', FLUSH_OK);

}));

1 个答案:

答案 0 :(得分:1)

使用python-nav-beginning-of-defun方法而不是event可以指定响应正文的类型。

flush

您还可以选择设置其他属性,例如const req = httpMock.expectOne('some-url'); req.event(new HttpResponse<boolean>({body: true})); status

HttpResponse docs

Original answer