Can't call a global function

203 views Asked by At

Writing a unit test for Apigee JS policy.

I am trying to call context.getVariable("env") from send Msg () but context is not recognized as a global and hence I cant callcontext.getVariable().

edit: I cant add global.context.getVariable("env") as it is an Object of Apigee's platform

    global.context={}
    global.context.getVariable=function(){}

    function logger(){

        function log(msg){

           this.sendMsg(msg)
        }

        var sendMsg = function (){
            context.getVariable("env")
        }

        return {
            log:log,
            sendMsg:sendMsg
        }
    }

    logger().sendMsg()//TypeError: context.getVariable is not a function

Why is it happening? and what should I do?

I have tried calling logger().sendMsg.apply(global) is that ok?

0

There are 0 answers