Reputation: 122
I have a node service which uses AMQP to perform a remote procedure call, so it publishes a messages to a given amqp exchange and expects a response on a given amqp queue with the results of that call.
I am looking for a good unit test strategy which mocks the amqp connection can send a message based on a given input. I have looked into amqp-mock module but this seems to require a connection to a real amqp server and this was something I wanted to avoid.
Has anyone implemented anything similar or have a good strategy for this?
Upvotes: 2
Views: 3609
Reputation: 147
You easily mock require by using the "a" module:
// Example faking require('./foo') in unit test:
var fakeFoo = {};
var expectRequire = require('a').expectRequire;
expectRequire('./foo').return(fakeFoo);
// in sut:
var foo = require('./foo'); // returns fakeFoo
Upvotes: 1