我们如何在角度测试httpresource? 我喜欢Angular的新httpresource,它做了很多我很久以来一直想要的事情。它确实可以使生活更轻松。 但是,我在用茉莉花测试httpresource时遇到麻烦...

问题描述 投票:0回答:0
fit('should call the expected URL', () => { TestBed.runInInjectionContext(() => { const resource = service.fetchSettings(); //httpResourceRef resource.reload(); const req = httpMock.expectOne(`${environment.baseUrls.api.wellcomm}/1.0/cluster/getPendingSettings`); //HttpTestingController expect(req.request.method).toBe('GET'); req.flush({}); }); });

我希望这会触发请求方法,以使测试通过。但是,不是。

我知道它与组件如何读取它有关,但是我该如何模仿呢?每次使用此信息时,我都必须构建一个读取和呈现数据的组件吗?

您应该使用

HttpTestingController
,因为已经进行了测试。
HttpClient

angular signals
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.