Test çerçevesi olarak mocha kullanıyorum ve HTTP 204
durum kodu döndüren bir son noktaya karşı kullanan bir DELETE
isteğini denemeye çalışıyorum.Nock isteği keser ama boş nesneyi döndürür
it('should logout user', (done) => {
nock(<domain>)
.log(console.log)
.delete(path)
.reply(204, {
status: 204,
message: 'This is a mocked response',
});
api.logout(token)
.then((response) => {
console.log('IS DONE?--->', nock.isDone());
console.log('RESPONSE--->', response);
done();
})
.catch((error) => {
console.log('ERROR--->', error);
});
});
Bu aşağıdaki çıktı döndürür::
İşte Test kodudur
matching <domain> to DELETE <domain>/<path>: true
(the above line being generated by the .log method in nock)
IS DONE?---> true
RESPONSE---> {}
Eğer log()
ve isDone()
nock yöntemlerle belirtildiği gibi istek düzgün ele ediliyor görebileceğiniz gibi
response
nesnesi boş bir nesnedir, bu nedenle döndürülen HTTP durum koduyla ilgili iddialar yapmak mümkün değildir (bu örnekte
204
)
Burada nelerin eksik olabileceğine dair bir fikriniz var, neden reply()
yöntemi boş bir nesneyi döndürüyor?
UPDATE Burada
logout
yöntemi için kodu remove
yöntem DELETE
HTTP yöntemiyle bir fetch
talebi için bir sarıcı.
logout(token) {
return remove(
this.host,
END_POINTS.DELETE_TOKEN,
{
pathParams: { token },
},
{
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
);
}
"api.logout" kodunun anlamı nedir? Bu, "nock" tarafından sağlanan bir şey gibi görünmüyor. Bana öyle geliyor ki orada bir hata olabilir. – Louis
Son nokta için bir DELETEHTHT yöntemini temsil eder, iyi çalışır ve çıktıda gösterildiği gibi doğru şekilde kesilir gibi görünüyor, kodu dahil etmek için soruyu güncelledim, daha önce dahil etmedim karışıklığı önlemek. – rfc1484