If this is not the case, you will want to add onOffto the module so that your test can enter a stub.
var sinon = require("sinon");
var process = require("process");
var onOffModule = require(PATH_TO_ONOFF);
var gpio = require(PATH_TO_GPIO);
var onOffStub;
var fakeListenPort;
beforeEach(function () {
sinon.stub(process, "emit");
fakeListenPort = {
this.watch = function(callback) {
this.callback = callback;
};
};
onOffStub = sinon.stub(onOffModule, "onOff", function () {
return fakeListenPort;
});
});
describe('the GpioPlugin module', function () {
it('example test', function () {
gpio.listenEvents("evtId", OPTS);
assert(onOffStub.callCount === 1);
fakeListenPort.callback(null, "Value");
assert(process.emit.calledWith("evtId", "Value"));
});
});
. onOff , .
, onOff , , , onOff. , , , , - proxyquire.