node-red / node-red-node-test-helper

A test framework for Node-RED nodes
Apache License 2.0
57 stars 41 forks source link

.send spy common across all nodes #67

Open joepavitt opened 1 year ago

joepavitt commented 1 year ago

Problem Summary

I'm trying to write tests for the new Dashboard 2.0. In doing so, I have a passthru option, which when disabled, does not send a message on to any connected nodes.

As such, I needed to write a test that check the sinon.spy() on node.send() did not run. However, it does.

Upon investigation with @knolleary, we discovered that all nodes in the helper share a single spy on the respective .send(), this means that any node sending a message would trigger this spy, thus making it impossible to register whether or not the node.send() was not run for a given node we cared about.

Temporary Workaround

In order to circumnavigate the issue, we have used the following pattern utilising setTimeouts and.a helper-node: