Angular httpClientTestingModule模拟
我有功能Angular httpClientTestingModule模拟,angular,unit-testing,jasmine,mocking,Angular,Unit Testing,Jasmine,Mocking,我有功能 delete(event, envName) { event.stopPropagation(); this.toogleBtn(event); this.modal.show('Confirm', envName ).then(() => { this.http.delete(myAddress + envName, { headers: new HttpHeaders().set('Authorization', `Bearer token}`) }).su
delete(event, envName) {
event.stopPropagation();
this.toogleBtn(event);
this.modal.show('Confirm', envName ).then(() => {
this.http.delete(myAddress + envName, {
headers: new HttpHeaders().set('Authorization', `Bearer token}`)
}).subscribe(response => {
this.getDetails().then(res => {
this.details = res;
});
});
});
}
我想使用httpClientTestingModule模拟http请求,如下所示:
it('should delete', () => {
const event = new Event('click');
const envName = 'env';
spyOn(component, 'toogleBtn');
spyOn(event, 'stopPropagation');
spyOn(component.modal, 'show').and.returnValue(Promise.resolve());
component.deleteEvnBtn(event, envName);
const req = httpClientMock.expectOne(myAddress + envName);
req.flush('data');
});
但是我在httpClientMock.expectOne中收到一个错误:
错误:应为条件“匹配URL:myAddressWithEnvName”提供一个匹配请求,但未找到任何请求
其中地址与函数中的地址完全相同。或者您的测试应该是
异步的
,或者您的然后
方法没有被调用。或者您的测试应该是异步的
或者您的然后
方法没有被调用