arunoda / nodemock

Simple Yet Powerful Mocking Framework for NodeJs
http://arunoda.me
MIT License
75 stars 1 forks source link

Mocking event emitters #10

Closed soggie closed 13 years ago

soggie commented 13 years ago

How do I mock event emitters? In my current project I use a factory pattern to achieve dependency injection on all modules (every module has a make() function that is basically a constructor injection thingy), and I have no trouble mocking NodeJS core API but have no idea how to mock event emitters (other than writing my own).

How does nodemock do this?

arunoda commented 13 years ago

nodemock works great with dependency injection. But with the core modules and other it'll be little tricky. So there is no such direct solution in nodemock and it does only mocking. Mocking event emitters in very tricky.

But You can it as follows. //Start of the Test

var event = require('event'); var oldOne = event.EventEmitter; event.EventEmitter = YourVersion;

//Do the test

event.EventEmitter = oldOne;

soggie commented 13 years ago

I guess that would work, although after posting that I did a double take and figured trying to mock a emitter is kind of useless anyway since emitters are isolated code by themselves. Feel free to close this issue. :p

arunoda reply@reply.github.com wrote:

nodemock works great with dependency injection. But with the core modules and other it'll be little tricky. So there is no such direct solution in nodemock and it does only mocking. Mocking event emitters in very tricky.

But You can it as follows. //Start of the Test

var event = require('event'); var oldOne = event.EventEmitter; event.EventEmitter = YourVersion;

//Do the test

event.EventEmitter = oldOne;

Reply to this email directly or view it on GitHub: https://github.com/arunoda/nodemock/issues/10#issuecomment-1547948

arunoda commented 13 years ago

It just closed :P