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:
- Wire the node we want to watch to a
helper-node (Helper 1)
- Add a
complete node with a scope set the node id of the node we care about
- Wire a
helper-node (Helper 2) after the complete node as we can't monitor on('input') for `complete nodes.
- Define a
msgSent = false in the scope of the test
- Add an
on('input') for Helper 2 and within it, set the variable msgSent to true
- Add an
on('input') for the helper node after the complete.
- Inside this event handler, set a timeout (e.g. 50ms) to ensure that Helper 2 handles logic first, then check that
msgSent is true/false, depending on the desired outcome of the test
Problem Summary
I'm trying to write tests for the new Dashboard 2.0. In doing so, I have a
passthruoption, 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()onnode.send()did not run. However, it does.Upon investigation with @knolleary, we discovered that all nodes in the helper share a single
spyon the respective.send(), this means that any node sending a message would trigger this spy, thus making it impossible to register whether or not thenode.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:helper-node(Helper 1)completenode with ascopeset the node id of the node we care abouthelper-node(Helper 2) after thecompletenode as we can't monitoron('input')for `complete nodes.msgSent = falsein the scope of the teston('input')for Helper 2 and within it, set the variablemsgSenttotrueon('input')for thehelpernode after thecomplete.msgSentistrue/false, depending on the desired outcome of the test