1

I have a file with format below which uses certain module.

let module = require('modulename')
let r = module()
r.post(variable, callbackFunction)
r.post(variable, variable, variable, callbackFunction)

I am trying to mock this two function using proxyquire as given below

let module= function(){
    return {
        post: (variable, callback) => {
            //some codes
            return callback(error, res)},
        post: (variable,variable,variable, callback) => {
            //somecode
            return callback(error, res)}
    }}
let mock = proxyquire(filepath,{'modulename':module})

Since it contain two function with same name, i am unable to mock these two post function as the function call goes to only one function(second function). How to resolve this? Anyody got any idea? I am fairly new to unit testing and proxyquire

daedsidog
  • 1,732
  • 2
  • 17
  • 36
  • So you want to mock the `r.post` method returns different value based on parameters, right? – Lin Du Mar 23 '23 at 03:31

0 Answers0