mercredi 20 février 2019

Unit testing methods declared inside another method in Node

i have a node module of the following format

'use strict’;

/// require dependencies here 

function outerFunc1(a,b,c) {

function f1() {
    return f2()
}

function f2() {
return 2
}

}
const choose = (type) => {
let  funcToCall
switch (type) {
    case “func1”:
        funcToCall = outerFunc1;
        break;
    case “func2”:
        funcToCall = outerFunc2;
        break;
}
return funcToCall;
}

module.exports = (function() {
return {
    choose
};
})();

Can any one tell me how to unit test function f2 and f1 or in other words how can i invoke the same , is there any way to achieve the same like using reflection api or any other way using rewire or sinon .





Aucun commentaire:

Enregistrer un commentaire