helper.getNode return null

Hi all,

I am trying to develop unit test for my node-red flows.
However i am facing issue with helper.getNode() function.

It returns null after passing node_id. These node id's are correctly retrieved using loadFlowFile() function and you can see the node-id's in output code.

import "mocha";
import { expect } from "chai";
import * as sinon from "sinon";

const requiredNodes = [

describe("Node-RED flow test", () => {
    const helper = require("node-red-node-test-helper");

    let inputNodeIds: string[] = [];
    let outputNodeIds: string[] = [];

    function loadFlowFile() {
        const flow: any[] = require("../src/flows.json");

        flow.forEach((node) => {
            console.log(" Node Is = ",node)
            if (node.type === "inject") {
                inputNodeIds[inputNodeIds.length] =;
                node.type = "helper";
            if (node.type === "debug") {
                outputNodeIds[outputNodeIds.length] =;
                node.type = "helper";
        return flow;

    before(() => {

    beforeEach((done) => {

    afterEach((done) => {
        helper.unload().then(() => {

    function runFirstTest(done: Mocha.Done) {
        const flow = loadFlowFile();
        helper.load(requiredNodes, flow, () => {

            console.log("Input Node IDs = ",inputNodeIds)
            console.log("Output Node IDs = ",outputNodeIds)


            const inputNode = helper.getNode(inputNodeIds[0]);
            const outputNode = helper.getNode(outputNodeIds[0]);

            console.log("Input Node = ",inputNode)
            console.log("Output Node  = ",outputNode)

            outputNode.on("input", (msg: any) => {
                try {
                    expect(msg.payload).to.equal("payload contains 0")
                } catch (e) {

            inputNode.wires[0].forEach((wire: string) => {
                const node = helper.getNode(wire);
                console.log(" Node  = ",node)
                node.receive({ payload: 123450 });

    it("should send 'payload contains 0' when the first digit is 0", (done) => {

The Output is

Input Node IDs =  []
Output Node IDs =  [
Input Node =  null
Output Node  =  null
    1) should send 'payload contains 0' when the first digit is 0

  0 passing (2s)
  1 failing

  1) Node-RED flow test
       should send 'payload contains 0' when the first digit is 0:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (C:\Users\Abbad Zafar\Desktop\node-red\node-red-email\test\flow-test.ts)

Welcome @Zafar

Can you confirm whether you’re trying to develop flows or custom nodes for node red?

The package is for custom node development, not flows

Hi, @marcus-j-davies . Yes, i am trying to test the nodes for node-red

Ok, as your developing your own custom node modules - i have recategorised this post

I’m just about to head out - but a member of the forums may be around.

1 Like


I don't see where you are loading your custom node?
are you sure this is for your own custom nodes, as in you have developed nodes that users can install?

As I said, this package is for developers, developing node modules for Node RED, not writing flows.
Example: I don't see a require for your custom written node :man_shrugging:

I have moved this back out of Developing Nodes, unless I can be corrected, apologies if so.

Maybe this is what you are looking for?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.