I'm developing a node that uses a library to call out to an external system. To unit test I need to mock it. What do I do? My node is roughly like this:
const backend = require('./theDarkSide`);
module.exports = function (RED) {
function LightSaber(config) {
const node = this;
node.color = config.color || 'RED';
node.on('input', (msg, send, done) => {
backend.fight(node.color, msg.payload.jedi)
.then(result => {
send(result);
done();
});
// catch omitted here
});
}
}
RED.nodes.registerType('light-saber", LightSaber);
}