Node js stubbing issue

Issue

This Content is from Stack Overflow. Question asked by Surya E R

So, I am trying to write unit tests for a lambda handler. It is just a classic exports.handler
function expression.I require this using const {handler}=require( "."). Just after requiring it, there’s a const which makes an api call to a third party service to obtain few details for further processing.

At my unit testing side, I am running into Assertion error of not passing the required key for that third party service.

const analytics = new Analytics(process.env.yourWritekey, analyticsOptions);

exports.handler=async(event,context,callback)=>{

  //this part is business logic
}

So my question is , how did I just test the handler by stubbing the third party api call?



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?