Testing functions required by my node

I have a node into a module like below:

module.exports = function(RED) {
//requires and global vars here
var host = RED.settings.host || "localhost";
var request;

    function  myNode(config) {
        this.request = config.request;
        parseJSON(request);
        // do more things here
    }
    RED.nodes.registerType("my node", myNode);

    function parseRequest(request) {
        let json = {};
        try {
            json = JSON.parse(request);
        } catch (e) {
            node.error(RED._("parsing error occur", {location: "parse"}), request );
        }
        return json;
    }
}

I'm trying to do some unit test for the above node through node-red-node-test-helper and I wonder if there is a way to test the functions needed by the node "myNode" in this case "parseRequest". There could be more complex functions than the one I used on the example so, considering that scenario, if in my test file code I want to do a unit test for that "parseRequest" function, I face some obstacles:

  1. I have no way of invoke the "parseRequest" function since the test file, when try to do something like the below, does not recognize like a function.
var mynode = require("myNode.js");
mynode.parseRequest({id:1, name:"qwerty"});
  1. my exported module need an instance of RED object as parameter.
  2. the only way I can access that function is if I take it out from the node module and exports it separately, but can trigger another error because of the use of RED into the catch.

I hope you understand my point here
Thanks for the help

This should hopefully help you out. :smile:

https://nodered.org/docs/creating-nodes/first-node#unit-testing