0

how to call the b function, since b will return the message.Please see the below snippet.

i have posted this question related to this. But i didn't get any answer so i split the question.

how to get the string from the below snippet.

const a = () => {
   return b((log) => {
     return `log message will be ${log.message}`
   })
}

if i execute a() // it will show

 (log) => {
 return `log message will be ${log.message}`
}

confused of this format i tried a()(), but throws error, how should i call this b method

Learner
  • 8,379
  • 7
  • 44
  • 82
  • what is `b` doing? – Nina Scholz Feb 02 '19 at 09:51
  • b is a third party module function , can u check this question https://stackoverflow.com/questions/54491134/testing-a-function-inside-another-function-using-jest – Learner Feb 02 '19 at 09:54
  • Where is `log` btw? – Maheer Ali Feb 02 '19 at 09:55
  • @MaheerAli, can you check this one which is related to this i have explained it over there https://stackoverflow.com/questions/54491134/testing-a-function-inside-another-function-using-jest – Learner Feb 02 '19 at 09:56
  • _"i tried a()(), but throws error"_ because `a()` returns a function that expects an object with a `message` property as parameter. – Andreas Feb 02 '19 at 10:17
  • @Andreas okay can you check this question https://stackoverflow.com/questions/54491134/testing-a-function-inside-another-function-using-jest – Learner Feb 02 '19 at 10:18

1 Answers1

1

By getting this function as call of a(),

(log) => {
    return `log message will be ${log.message}`
}

you need another call with an object for getting log.message in a string.

const
    b = fn => fn, // assuming this
    a = () => {
        return b((log) => {
            return `log message will be ${log.message}`
        })
    };

console.log(a());
console.log(a()({ message: 'foo' }));
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392