0

Trying to do expect statement on Non-exposed method in node.js..

myfile.js

function main() {
    try{
    } catch(err) {
        a();
    }
}       
           
function a() {
    return true/false
}
module.exports = {
    main:main
}

a() is not exported its internal to myfile.js. Now my requirement is in test file how can i do expect(a()).to.be.true. Is it other way to mock this function and do expect statement?. Please share your ideas;

Subburaj
  • 5,114
  • 10
  • 44
  • 87
  • Unless you can force the error in `main()` to take that path, `a` needs to be exported somehow. See [this answer](https://stackoverflow.com/a/54116345/1318694) in the dupe for a method to export functions but a `B` module, but not `A`. – Matt Jul 06 '22 at 06:28
  • Does this answer your question? [How can I unit test non-exported functions?](https://stackoverflow.com/questions/54116070/how-can-i-unit-test-non-exported-functions) – Matt Jul 06 '22 at 06:29
  • @Matt Thanks for sharing.Already have gone through the post , but it doesn't solve my problem, they are exporting it in someway. – Subburaj Jul 06 '22 at 06:30
  • Well, it provides the methods you can use to test it – Matt Jul 06 '22 at 06:59

0 Answers0