I'm trying to inject a gateway by using a node module. Not sure if I can do this because I get a 'object is not a function error'
on the line var response = new controller(gateway).find();
or maybe I should be able to do this with a node moduile, but not doing this right.??
Note: Although the code in the controller is not using the gateway yet, I want to be able to inject it for now just to make sure I can.
someFile.js
var controller = require('someController');
var gateway = require('someGateway);
var response = new controller(gateway).find();
someGateway.js
'use strict';
module.exports = function(){
var _data;
return {
data: function(someData){
_data = someData;
},
find: function(){
return _data;
}
};
}();
someController.js
'use strict';
module.exports = function(gateway){
var _gateway = gateway;
return {
find: function(searchText){
var response = {};
if(typeof searchText === "undefined"){
response.statusCode = 400;
}
return response;
}
};
}();
UPDATED:
I tried changing it to this:
someFile.js
var controller = require('someController');
var response = controller.find();
someControllerjs
'use strict';
var Controller = function(){
var _find = function(searchText){
var response = {};
if(typeof searchText === "undefined"){
response.statusCode = 400;
}
return response;
};
return {
find: _find
};
}();
module.exports = Controller;
I'm trying to go with the pattern this dude has but still I get the same error. http://rob.conery.io/2012/02/25/testing-your-model-with-mocha-mongo-and-nodejs/