You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
this might be a little off topic but nevertheless I give it a try. I am using rabbit.js in a node.js project and I really would like to implement some unit tests for my classes that use rabbit.js. I've spend a whole day to play around with jasmine-node, rewire and sinon but I am totally lost. Maybe it is because I've never tried to implement unit tests for asynchronous code and maybe it is because I am not that experienced in programming java script. Most likely it is because of both :-)
Can anyone recommend a way to implement unit tests for code like this one? How would you test, if calling bar() results in publishing a message?
Thankful for any hints,
Tobias
varrabbitjs=require('rabbit.js');functionFoo(rabbitHost,rabbitPort){this.rabbit=rabbitjs.createContext('amqp://'+rabbitHost+':'+rabbitPort);};Foo.prototype.bar=function(){varself=this;this.rabbit.on('ready',function(){varsocket=self.rabbit.socket('PUBLISH');socket.end('hello-rabbit','Here I am');});};module.exports=Foo;
The text was updated successfully, but these errors were encountered:
functionFoo(context){this.context=context;}Foo.prototype.bar=function(){varself=this;this.context.on('ready',function(){varsocket=self.context.socket('PUBLISH');socket.end('hello-rabbit','Here I am');});};module.exports=Foo;
Then, I could test it with (shameless plug) something like nodemock.
varnodemock=require('nodemock');varctrl={};varfrabbit=nodemock.mock('on').takes('ready',function(){}).ctrl(1,ctrl);frabbit.mock('socket').takes('PUBLISH');frabbit.mock('end').takes('hello-rabbit','Here I am');varFoo=require('./foo');// Your filevarfoo=newFoo(frabbit);foo.bar();ctrl.trigger(10,20);// triggers the callback of the "on" methodfrabbit.assert();
Hi
this might be a little off topic but nevertheless I give it a try. I am using rabbit.js in a node.js project and I really would like to implement some unit tests for my classes that use rabbit.js. I've spend a whole day to play around with jasmine-node, rewire and sinon but I am totally lost. Maybe it is because I've never tried to implement unit tests for asynchronous code and maybe it is because I am not that experienced in programming java script. Most likely it is because of both :-)
Can anyone recommend a way to implement unit tests for code like this one? How would you test, if calling
bar()
results in publishing a message?Thankful for any hints,
Tobias
The text was updated successfully, but these errors were encountered: