我正在为angular应用编写单元测试,我想检查是否正在调用“ DELETE” API(这将删除帐户),并且正在模拟服务器响应。
如果API成功,则API返回{状态:“成功”},如果失败,则返回{状态:“失败”}。 单击按钮后,将使用删除方法调用API。
_flusher()
测试失败错误:预期对标准“匹配URL:/ api / accounts / Acc444”有一个匹配请求,但没有找到。
尽管此API存在,但是当我单击按钮时就会调用
component.ts
it ('should delete account, if account already exist', ()=> {
let record = {
"accountid":"Acc444"
}
component.record = record;
fixture.detectChanges();
let deleteButtonDOM = fixture.debugElement.query(By.css('#deletebtn'));
deleteButtonDOM.triggerEventHandler('click','');
fixture.detectChanges();
const req = _HttpTestingController.expectOne('/api/accounts/'+record.accountid);//fails here
expect(req.request.method).toBe("DELETE");
req.flush({status:"SUCCESS"});
expect(component.consoleMessages.includes("POST: SUCCESS in /api/accounts")).toBeTruthy;
})