Does the node-red-test-helper support multiple outputs?

I've got the hang of writing unit tests in mocha using the test helper. It's great.
I'm trying to figure out to test an output on a second output of a node.
Is this supported by the test helper?

I can't think why it wouldn't be. What have you tried?

Here's a snippet of what I thought would be the way.

receiver.on("input", function (msg, msg2) {
        try{
          //msg is good. 
          //msg2 is undefined
          done();
        }catch(err){
          return done(err);
        }

Hi @kareem613

Nodes only receive one message at a time. So if your sending node sends two messages, the receiving node will have its "input" event called twice - once for each message.

1 Like

depends what you mean by second output... if you mean a sequence then you have to count the incoming messages and check each in turn. If you mean a node has multiple output pins then you need to create/wire a helper to each.

1 Like

Ah that's it. I meant a second output. Wiring up a second node makes perfect sense.
Thanks!

I have a node (node-red-contrib-mytimeout - countdown timer) that outputs events on 2 outputs. The first outputs is a JSON event meant to turn on or off a device. The second output is a JSON event that is roughly send every second with the time remaining and the state of the timer. I'm not suggesting that this is the best way or even correct but it is a pointer. :slight_smile:

Here's some code for testing a node with 2 outputs:

const should = require("should");
var   helper = require('node-red-node-test-helper');
var   myNode = require('../mytimeout.js');

helper.init(require.resolve('node-red'));

var nom =  'MyTimeout';

describe('mytimeout Node', function () {

  beforeEach(function (done) {
    helper.startServer(done);
  });

  afterEach(function (done) {
    helper.unload();
    helper.stopServer(done);
  });

  it('Should turn off, Tx 0', function (done) { // Passes
    var flow = [
      { id: "n1", type: "mytimeout", name: nom, output: 2, wires:[["n2"], ["n3"]] },
      { id: "n2", type: "helper" }, // Commands
      { id: "n3", type: "helper" }  // Ticks
    ];
    helper.load(myNode, flow, function () {
      var fini = 0;

      var n3 = helper.getNode("n3");
      var n2 = helper.getNode("n2");
      var n1 = helper.getNode("n1");

      // Okay the fini++ seems like a good idea but if I get 2 n2 or 2 n3 I might gets a false done
      n2.on("input", function (msg) {
        msg.should.have.property('payload', 'off');
        fini++;
        if(fini > 1) {
          done();
        }
      });

      n3.on("input", function (msg) {
        msg.should.have.property('payload', 0);
        fini++;
        if(fini > 1) {
          done();
        }
      });

      n1.receive({ payload: '0' });
    });
  });
});