Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.send spy common across all nodes #67

Open
joepavitt opened this issue Sep 8, 2023 · 0 comments
Open

.send spy common across all nodes #67

joepavitt opened this issue Sep 8, 2023 · 0 comments

Comments

@joepavitt
Copy link
Contributor

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant