nock sample
"use strict";
/* jshint esversion: 6 */
const axios = require('axios');
const nock = require('nock');
function fnRequest(_stComment, _stSuffix = '', _stS = '') {
axios({
method: 'get',
url: `http${_stS}://example.com/${_stSuffix}`
})
.then((res) => {
console.log(`req-${_stComment} - success`); //del
})
.catch((err) => {
console.log(`req-${_stComment} - error`); //del
});
}
// --- nock
nock.disableNetConnect();
nock('http://example.com/')
.get('/')
.reply(200, { resp: 'ok' });
// ---
fnRequest('01');
// nock.cleanAll();
// nock.enableNetConnect();
fnRequest('02', '', 's');