jaredhanson / electrolyte

Elegant dependency injection for Node.js.
MIT License
564 stars 61 forks source link

Add tests to example project #15

Open saverchenkov opened 9 years ago

saverchenkov commented 9 years ago

I am trying to find a typical pattern of mocking dependencies using electrolyte. Some example tests would be helpful. Thank you!

jaredhanson commented 9 years ago

I'll take a pull request for this, but writing extensive example code is not a priority for me personally.

mikalai-sauchanka commented 9 years ago

+1 to this feature. API method to replace a single module in container would be enough.

digitalwm commented 9 years ago

+1 to this feature

joeltello commented 9 years ago

+1

pwlmaciejewski commented 9 years ago

+1

I've created a RequireBin for my solution: http://requirebin.com/?gist=5f1c8f5855a69aa3edc0 .

It's not pretty but it works well for isolated example. In live project though it needed to execute _loadModule method after replacing the dependency.

I would love to see some method to replace method in container. Also, it would be nice to have a section on the topic in readme.

charlires commented 9 years ago

+1

gimre commented 9 years ago

hey, created a pull request (https://github.com/jaredhanson/electrolyte/pull/16) for a simple mocking extension to the Container class

usage:

ioc.mock( 'real/component', 'mock/component' );
colthreepv commented 9 years ago

+1 on this. My tests looks like:

var ioc = require('electrolyte');
var
  common = ioc.create('commonfuncts'),
  config = ioc.create('config')
  app = ioc.create('app');

// actual test code
common.testMyApp(app, config);

There are ways to shorten this boilerplate?

cades commented 9 years ago

+1

mattgi commented 9 years ago

@jaredhanson you suggest that a PR will be accepted. As one exists, is there an ETA on when it will be merged?

dkushner commented 9 years ago

@jaredhasnon, has there been any progress on this? Given that simplicity of testing is one of the main benefits of IoC-enabled applications, I'd expect that'd be one of the first examples on the page.

BLaurent commented 9 years ago

+1