# Unit testing with config nodes?

**URL:** https://discourse.nodered.org/t/unit-testing-with-config-nodes/10863
**Category:** General
**Created:** [6 May 2019 20:41 UTC](https://discourse.nodered.org/t/unit-testing-with-config-nodes/10863 "2019-05-06T20:41:53Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![darkbluestudios](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/darkbluestudios/32/8116_2.png) [@darkbluestudios](https://discourse.nodered.org/u/darkbluestudios)
#### Post date: [6 May 2019 20:41 UTC](https://discourse.nodered.org/t/unit-testing-with-config-nodes/10863/1 "2019-05-06T20:41:53Z")

</div>

I really would like to have unit tests for all my nodes,  
as it helps quite a bit in different ways.

I'm having trouble understanding how to create my own flow for unit tests  
especially when there is a [configuration node](https://nodered.org/docs/creating-nodes/config-nodes) involved... Can anyone help?

I thought something like the following would work:

- where soql-query (node) references the config node (connection-emitter),
- I would just set the property on the node to the id of the config node...  
(that seems to be the case when inspecting the node when it actually loads...)  
unfortunately it doesn't seem to work. Well... the load calls, but then cannot be found by helper.getNode()

I made a configuration node (connection-emitter) with the following props: host, username, password, token  
and I would like to reference that configuration within another node (soql-query) with the following props: name:string, sfconn:connection-emitter, query:string and queryType:string - using inputType, target:string

This gives me an error that n1 fails the assumption - n1 should not be null

```auto
  it('should load/explorer/sf-soql-query', () => {
    const flow = [
      {id:'n1', type:'sf-soql-query', name:'Custom_Name', sfconn:'n2'},
      {id:'n2', type:'sf-connection-emitter', host:'SF_HOST', username:'SF_USERNAME', password:'SF_PASSWORD', token:'SF_TOKEN'}
    ];
    const testPromise = new Promise((resolve, reject) => {
      helper.load(soqlQueryNode, flow, () => {
        try {
          const n1 = helper.getNode('n1');
          assert.notEqual(n1, null, 'n1 should not be null');
          resolve();
        } catch(err){
          reject(err);
        }
      });
    });
    return testPromise;
  });

```

---

<div class="post-metadata">

### Author: ![darkbluestudios](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/darkbluestudios/32/8116_2.png) [@darkbluestudios](https://discourse.nodered.org/u/darkbluestudios)
#### Post date: [6 May 2019 20:58 UTC](https://discourse.nodered.org/t/unit-testing-with-config-nodes/10863/2 "2019-05-06T20:58:49Z")

</div>

Please note, I am using the beforeEach / afterEach recommended by the help docs

```auto
  beforeEach(function (done) {
    helper.startServer(done);
  });

  afterEach(function (done) {
    helper.unload();
    helper.stopServer(done);
  });

```

---

<div class="post-metadata">

### Author: ![darkbluestudios](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/darkbluestudios/32/8116_2.png) [@darkbluestudios](https://discourse.nodered.org/u/darkbluestudios)
#### Post date: [7 May 2019 16:23 UTC](https://discourse.nodered.org/t/unit-testing-with-config-nodes/10863/3 "2019-05-07T16:23:35Z")

</div>

So one quick update to the tests I've been attempting, it turns out helper.load accepts arrays of functions, so I tried sending it this code as-well, but also haven't had any luck with it...

```auto
  it('should load/explorer/sf-soql-query', () => {
    const flow = [
      {id:'n1', type:'sf-soql-query', name:'Custom_Name', sfconn:'n2'},
      {id:'n2', type:'sf-connection-emitter', host:'SF_HOST', username:'SF_USERNAME', password:'SF_PASSWORD', token:'SF_TOKEN'}
    ];
    const testPromise = new Promise((resolve, reject) => {
      helper.load([soqlQueryNode,soqlQueryNode], flow, () => {
        try {
          const n1 = helper.getNode('n1');
          assert.notEqual(n1, null, 'n1 should not be null');
          resolve();
        } catch(err){
          reject(err);
        }
      });
    });
    return testPromise;
  });

```

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [21 December 2020 13:56 UTC](https://discourse.nodered.org/t/unit-testing-with-config-nodes/10863/5 "2020-12-21T13:56:46Z")

</div>


