
[英]Error: Expected one matching request for criteria "Match method: GET, URL: /users", found none
[英]DELETE request: Error: Expected one matching request for criteria “Match URL: /api/accounts/Acc444”, found none. though API exist
我正在为 angular 应用程序编写单元测试,我想检查是否正在调用“删除”API(这将删除帐户)并且我是 mocking 服务器响应。
如果 API 成功,则 API 如果失败则返回 {status:"SUCCESS"} {status:"FAILURE"}。 单击按钮后,这将使用删除方法调用 API。
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;
})
测试失败错误:预期有一个对条件“匹配 URL:/api/accounts/Acc444”的匹配请求,但没有找到。
虽然这个 API 存在并且当我点击按钮时被调用
组件.ts
this.spinner.show();
this.http.delete('/api/accounts/' +this.record.accountid)
.subscribe(res => { ...})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.