Skip to content

Instantly share code, notes, and snippets.

@ORESoftware
Last active February 14, 2016 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ORESoftware/0c772aedd3630bb54f27 to your computer and use it in GitHub Desktop.
Save ORESoftware/0c772aedd3630bb54f27 to your computer and use it in GitHub Desktop.
Dependency injection for Suman example
//use your own version of this file at the root of your project to configure dependency injection
module.exports = (suman) => { //load async deps for any of your suman tests
suman.configure({
'request': function () {
//* but we could mock 'request' and reference that mock request somewhere in our project by returning the below
// return require('./mock-request');
return require('request'); //this is not very useful, but below we can see useful asynchronous loading of deps
},
'socketClient': function (cb) {
const client = require('socket.io-client')('http://localhost:3000');
client.on('connect', cb);
client.on('error', cb);
},
'dbQueryAllUsers': (cb) => {
var db = require('./db/postgres');
db.sync().then(function () {
return db.users.find();
}).then(function (users) {
cb(null, users); //send 'users' as a value to any test that wants the value
}).catch(function (err) {
cb(err);
});
},
'dbQueryAllPosts': (cb) => {
var db = require('./db/postgres');
db.sync().then(function () {
return db.posts.find();
}).then(function (posts) {
cb(null, posts); //send 'users' as a value to any test that wants the value
}).catch(function (err) {
cb(err);
});
},
'redisClient': function () {
return require('./db/redis'); //return a dep from our project
},
'mockServer': function () {
var mockServers = require('./mock-servers');
mockServers.use('local');
return mockServers.setup(); //returns a promise
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment