尝试验证数据库查询的超时,但无法通过 HttpTestingController 实现。
不确定如何设计 UT。在这个设置中,应该在哪里添加超时。
it('test timeout', () => {
service.getData('2025-10-12', '2025-10-16').subscribe(
{
next: data => {
expect(data).not.toBeNull();
},
error: error => {
expect(error).toBeNull(); // handling all missing keys
}
}
);
// mocking endpoint - binding
const response = httpController.expectOne({
method: 'GET',
url: RestServerSA.RELEASES_OVERVIEW_RANGE
});
// mocking response from endpoint
response.flush({});
});
您可以使用 来引入延迟
promises
。我们setTimeout
在承诺中使用 来resolve
在一定时期后进行延迟。使用方法如下:
fakeAsync
您也可以尝试和的组合tick
,但我不赞成这样做,因为它已经与类似flush
。