Unit tests for Function node

Hi there,

I know Node-RED is all about low code, but on production and with experienced devs, the use of function nodes saves time and nodes (e.g. Switches, Changes, etc) on the canvas.

I think it would be productive if we can unit-test the function nodes the Node-RED way.

For example, you can have another tab in the function's configuration that says unit test, where you specify a list of inputs and expected outputs. Or it could be a full-blown mocha test suite.

And then maybe there's a button somewhere, maybe next to the Deploy node, that says Test all the function nodes.

When you click on this, it'll just trigger (run) all the function nodes with the inputs and compare with the expected outputs set on the function's unit test tab, and of course, flag all the failed tests. I know this sounds simple, but it can be extended into a full-blown test suite with describe/it/expect/etc, more flexible ways to verify the result of the function.

2 Likes

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