我确定api被多次调用,我想确定api被调用了多少次,为此我正在使用httptestingcontroller。
const req = httpMock.expectOne('/ api / getrecords');失败
it('should return one object', () => {
var dummyObject : any[];
dummyObject = [
{
account: "shjdhjhs",
produc: "xyz",
feature: "ejfjf",
}
];
const req = httpMock.expectOne('/api/getrecords');
//fails, as this api is called many times
expect(req.request.method).toBe("GET");
req.flush( dummyObject);
expect(component.Financials.length).toBe(1);
expect(component.Financials).toEqual( dummyObject);
//test for how many times this api is getting called?
});
答案 0 :(得分:2)
我还没有亲自测试过,但是我认为您可以使用httpMock.match
来返回匹配请求的列表。该列表的长度应等于端点被调用的次数。
链接到文档:https://angular.io/api/common/http/testing/HttpTestingController#match