Friday, 26 July 2019

nock

nock is very useful to mock your network calls.


https://github.com/nock/nock


the times function is very useful.

if you don't call it, it will be just one time by default.

it is very useful, if your want to test a code which do retry with some special case e.g. status= 401.

then you can :

nock(baseURL)
.get('/xx/')
.times(2)
.reply(429);
nock(baseURL)
.get('/xx/')
.reply(200, [
{
name: 'peter'
}
]);


in this case, the first 2 times the endpoint called the server will return 429,    them the 3rd time call will return 200.

which help you to test your retry logic.

No comments:

Post a comment