nock: Support for simulating errors
Nock is excellent! Something that would make it even excellenter is if nock could be used to simulate connection level errors:
nock("http://api.example.com")
.get("/some/path")
.failWith(new Error("socket hang up"));
Especially since these can be otherwise cumbersome to test. Keep up the good work!
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 19 (1 by maintainers)
In the end i solved it with something like:
Which looks clean, it does not involve
delayand stuff, and as it seems to me it is enough to simulateETIMEDOUThaving in mind that im usingrequest-promiselib where i’m checking forETIMEDOUTlike:if (err.error && err.error.code === 'ETIMEDOUT')Same can be applied for
ENOTFOUND, ECONNRESET, ECONNREFUSED...Hi Guys I had this same issue with superagent when trying to test timeout, took about a whole weekend to put it together that it is because superagent always retries requests by default, in fact deafult is
3[http://visionmedia.github.io/superagent/#retrying-requests](see here) , so on the second retry nock has no url to match thats why you geton setting retry to
0one gets the correct error, and test passes… 🕺🏾 Hopefully this helps someoneI had the same experience as what mazley93 had using node-request-retry.