I would like to convert the below working code
const Client = require('node-rest-client').Client;
const Rest = new Client();
const useRestClient = (url,args,_next)=> {
return new Promise(resolve => {
Rest.post(url,args, (data,_response) =>
{
resolve(data);
})
})
}
to something like this:
const Client = require('node-rest-client').Client;
const Rest = new Client();
function callRestPost(resolve, url, args)
{
return Rest.post(url,args, (data,_response) =>
{
resolve(data);
});
}
const useRestClient = (url,args,_next)=> {
return new Promise(callRestPost);
}
Is this correct? The reason I am doing is, is to mock the Rest.post method for unit testing. I am restricted to using mocha sinon for testing and I am new to JS and node.js. Please help.