jeudi 31 mars 2016

TypeError: Object function has no method 'myMethod' , why cant find mocked method?

I already was looking for this question and found this question, but I cant see the connection to my problem :/

So this is my main.js file:

module.exports = function(client) {

    this.HangUpCall = function(caller,callback) {
        client.calls(caller).update({status: 'completed'}, function(err, call) {
            if(err) {
                console.log(err);
            }
        });
        callback();
    };
}

And I want to mock client. So I made a mock model like this:

module.exports = function() {
    this.calls = function(callSid){
            var update = function(obj,cb){
                console.log(obj);
                cb(false,true);
            };
    };
};

And here is the test file:

describe("testing HangUpCall",function(){
        it('should update caller status to completed',function() {
            var Client = require(__dirname +'path/Mockfile');
            var mockClient = new Client();
            EMGC = new MAINFILECONSTRUCTOR(twilio, Client, mockClient);
            EMGC.HangUpCall('CA1234',function(){

            });
        });
});

And yeah this is what the console sais:

TypeError: Object function () {
    this.calls = function(callSid){
            var update = function(obj,cb){
                console.log(obj);
                cb(false,true);
            };
    };
} has no method 'calls'

Aucun commentaire:

Enregistrer un commentaire