У меня реальная проблема с моим тестом, в то время как HTTP-вызов, который я успешно работал, смоделировал и возвратил, теперь не сбрасывается из теста и вызывает сбой теста. Я получаю сообщение об ошибке:
Cannot flush a cancelled request.
Сам по себе тест использует Jest / Cucumber в рамках среды тестирования по умолчанию, и все это работает правильно, поэтому проблема не возникает *
Часть «тогда» в моем тесте выглядит следующим образом:
then(
/^the payment authority should be sent as '(.*?)'$/,
fakeAsync(consent => {
tick();
flushBrandPropertyCall(httpTestingController);
flushQuoteStatusCall(httpTestingController);
flushReferenceDataCall(httpTestingController);
httpTestingController.verify(); //Similar to an assert just make sure page is stable before continuing
const submitBtn = fixture.debugElement.query(By.css('#continue-button')).nativeElement;
submitBtn.click();
const timeRequest = httpTestingController.expectOne(HttpUrl.Time);
console.log('Cancelled?', timeRequest.cancelled);
if (!timeRequest.cancelled) timeRequest.flush({ now: Date.now() });
flushBrandPropertyCall(httpTestingController);
tick(1500); // Not sure exact source - maybe modal messages?
const payRequest = httpTestingController.expectOne(HttpUrl.SinglePayment);
expect(payRequest.request.body.paymentAuthority).toEqual(consent);
payRequest.flush({ paymentStatus: 'CARD_PAYMENT_SUCCESS', authCode: '', policyNumber: 5555, quoteVersion: 20 });
httpTestingController.verify();
expect(true).toEqual(true);
})
);
});
И отменяется неудачный HTTP-вызов flushBrandPropertyCall), который выглядит следующим образом:
export const flushBrandPropertyCall = (controller: HttpTestingController) => {
const request = controller.expectOne('/web-services/rest/properties/removedForSecurity');
console.log(request)
request.flush([
{
id: 8,
brand: 'removedForSecurity',
key: 'openingTimes',
value:
'{"motor":{"SAT":{"from":"09:00","to":"18:00"},"MON":{"from":"08:00","to":"22:00"},"TUE":{"from":"08:00","to":"22:00"},"WED":{"from":"08:00","to":"22:00"},"THU":{"from":"08:00","to":"22:00"},"FRI":{"from":"08:00","to":"22:00"},"SUN":{"from":"10:00","to":"18:00"},"YYYY-12-25":"holiday","YYYY-12-26":"holiday","2017-01-02":{"from":"10:00","to":"18:00"}},"home":{"SAT":{"from":"09:00","to":"17:00"},"SUN":{"from":"10:00","to":"16:00"},"WEEKDAY":{"from":"08:00","to":"22:00"},"YYYY-12-25":"holiday","YYYY-12-26":"holiday","2017-01-02":{"from":"10:00","to":"18:00"}},"multicover":{"SAT":{"from":"09:00","to":"17:00"},"SUN":{"from":"10:00","to":"16:00"},"WEEKDAY":{"from":"08:00","to":"22:00"},"YYYY-12-25":"holiday","YYYY-12-26":"holiday","2017-01-02":{"from":"10:00","to":"18:00"}},"van":{"SAT":{"from":"09:00","to":"17:00"},"MON":{"from":"08:00","to":"21:00"},"TUE":{"from":"08:00","to":"21:00"},"WED":{"from":"08:00","to":"21:00"},"THU":{"from":"08:00","to":"21:00"},"FRI":{"from":"08:00","to":"21:00"},"SUN":{"from":"10:00","to":"16:00"},"YYYY-12-25":"holiday","YYYY-12-26":"holiday","2017-01-02":{"from":"10:00","to":"18:00"}}}'
},
{
id: 364,
brand: 'aaaaa',
key: 'csOpeningTimes',
value:
'{"motor":{"SAT":{"from":"09:00","to":"17:00"}, "SUN":{"from":"10:00","to":"16:00"},"MON":{"from":"08:00","to":"20:00"},"TUE":{"from":"08:00","to":"20:00"},"WED":{"from":"08:00","to":"20:00"},"THU":{"from":"08:00","to":"20:00"},"FRI":{"from":"08:00","to":"20:00"}},"home":{"SAT":{"from":"09:00","to":"17:00"},"SUN":{"from":"10:00","to":"16:00"},"MON":{"from":"08:00","to":"20:00"},"TUE":{"from":"08:00","to":"20:00"},"WED":{"from":"08:00","to":"20:00"},"THU":{"from":"08:00","to":"20:00"},"FRI":{"from":"08:00","to":"20:00"}},"van":{"SAT":{"from":"09:00","to":"17:00"},"SUN":{"from":"10:00","to":"16:00"},"MON":{"from":"08:00","to":"21:00"},"TUE":{"from":"08:00","to":"21:00"},"WED":{"from":"08:00","to":"21:00"},"THU":{"from":"08:00","to":"21:00"},"FRI":{"from":"08:00","to":"21:00"}}}'
},
{
id: 91,
brand: 'aaaaaa',
key: 'publicKey',
value:
'10001|AD0FA4B69A67FA53084A6208E9E248D33EC1251C1B091893CA7855672755352A44C372F6999CEA01BD9B34F4A08E64A1A8009E1596E4B992FCCB6888E721E6CF1DA3F5918DCDB7F9B461823CCACF867671B32CE487236D24BEB93CE448E9541537CC18668B0CCE60E9566D5E00F62C1636606ABCBA38DADFF9A898D37388852D698A27388849A4C5A9394233E55B14541A811C228888239A7B55C9F782F0C0EE56D283AA74F11025AF0E3A08C8CA545505853F0060D61F003DAD78B57EE53C86395EB6BF013CA2C85FD9B4E21C062770BFDC02EA3315CD60FC4ED8F83E4108B8479BB0DA2ADC6E84029026FBB4ACEB123220C174DE7821A01EAA2E98D3342E03'
}
]);
tick();
};
Я пытался посмотреть онлайн, но не могу найти информацию об этой ошибке. Кто-нибудь знает, почему запрос будет отменен из тестовой спецификации c с использованием HttpTestingController?
Я также console.logged requestOne и вот объект запроса
TestRequest {
request: HttpRequest {
url: '/web-services/rest/properties/removedForSecurity',
body: null,
reportProgress: false,
withCredentials: false,
responseType: 'json',
method: 'GET',
headers: HttpHeaders {
normalizedNames: Map {},
lazyUpdate: null,
headers: Map {}
},
params: HttpParams {
updates: null,
cloneFrom: null,
encoder: HttpUrlEncodingCodec {},
map: null
},
urlWithParams: '/web-services/rest/properties/removedForSecurity'
},
observer: InnerSubscriber {
closed: true,
_parentOrParents: null,
_subscriptions: null,
syncErrorValue: null,
syncErrorThrown: false,
syncErrorThrowable: false,
isStopped: true,
destination: {
closed: true,
next: [Function: next],
error: [Function: error],
complete: [Function: complete]
},
parent: MergeMapSubscriber {
closed: true,
_parentOrParents: null,
_subscriptions: null,
syncErrorValue: null,
syncErrorThrown: false,
syncErrorThrowable: true,
isStopped: true,
destination: [FilterSubscriber],
project: [Function],
concurrent: 1,
hasCompleted: true,
buffer: [],
active: 1,
index: 1
},
outerValue: undefined,
outerIndex: undefined,
index: 1
},
_cancelled: true
}