This question already has an answer here:
I am writing an http wrapper around a third party dependency and struggling with a way to test it.
Here is an example which returns a promise:
const tinyreq = require('tiny-req')
class Test {
makeRequest (method, url, body) {
return tinyreq({
method,
url,
body
})
}
}
What is a better way to test makeRequest
?
- To actually call this method using a method, url and body such as
GET
,http://example.com
and{}
- To create a stub for this function while resolving (with response body as success value) and rejecting (with error object as failure value) it subsequently in multiple tests.
P.S. I am using chai
, mocha
, sinon
and chai-as-promised
.
Aucun commentaire:
Enregistrer un commentaire