Let's supose that I have a javascript function that behaves like that:
function foo() {
/* unnecessary code...*/
const sendObjSomewhere = (param) => {/* anom function implementation */}
return {
async bar(obj) {
try {
obj.name = obj.name.replace(/\w/g, '');
await sendObjSomewhere(obj);
} catch () {
console.error('you messed up');
}
}
}
}
I tried to show only the important part -- the objName variable and the function. My goal is to test if the obj.name is formated properly.
I've tried to use some libs but, unfortunately, I'm only allowed to use mocha and node native assertions (even more unfortunately, not allowed to extend mocha with other libs). How can I intercept await sendObjSomewhere(obj); and see how the params are being sent? Any other ways to test it are very welcome.
I'm using mocha 9.1.3 and node 16