# Unit testing can't load node in my it block?

**URL:** https://discourse.nodered.org/t/unit-testing-cant-load-node-in-my-it-block/47288
**Category:** Developing Nodes
**Created:** [17 June 2021 10:05 UTC](https://discourse.nodered.org/t/unit-testing-cant-load-node-in-my-it-block/47288 "2021-06-17T10:05:54Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![zoujagger](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zoujagger/32/43460_2.png) [@zoujagger](https://discourse.nodered.org/u/zoujagger)
#### Post date: [17 June 2021 10:05 UTC](https://discourse.nodered.org/t/unit-testing-cant-load-node-in-my-it-block/47288/1 "2021-06-17T10:05:54Z")

</div>

hi guys,

I've node-red installed globally and from my custom node project i've installed

```auto
npm install node-red-node-test-helper node-red --save-dev

```

test fail when i run npm test from my custom node project.

```auto
 should be loaded:
     TypeError: Cannot read property 'should' of null

```

this is my test file

```auto
var should = require("should");
var helper = require("node-red-node-test-helper");
var mycsnode = require("../mycustom");

helper.init(require.resolve('node-red'));

describe('mycsnode Node', function () {

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

    it('should be loaded', function (done) {
        var flow = [{ id: "n1", type: "mycsnode", name: "test name" }];

        helper.load(mycsnode, flow, function () {
          var n1 = helper.getNode("n1");
          console.log('n1---', n1);
          try {
            n1.should.have.property('name', 'test name');
            done();
          } catch(err) {
            done(err);
          }
        });
      });

});

```

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [17 June 2021 10:20 UTC](https://discourse.nodered.org/t/unit-testing-cant-load-node-in-my-it-block/47288/2 "2021-06-17T10:20:06Z")

</div>

> [@zoujagger](#):
>
> `console.log('n1---', n1);`

what does this line ↑ show in console?

---

<div class="post-metadata">

### Author: ![zoujagger](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zoujagger/32/43460_2.png) [@zoujagger](https://discourse.nodered.org/u/zoujagger)
#### Post date: [17 June 2021 10:21 UTC](https://discourse.nodered.org/t/unit-testing-cant-load-node-in-my-it-block/47288/3 "2021-06-17T10:21:25Z")

</div>

hi thanks for your reply.  
this line show n1--- null

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [17 June 2021 10:24 UTC](https://discourse.nodered.org/t/unit-testing-cant-load-node-in-my-it-block/47288/4 "2021-06-17T10:24:42Z")

</div>

thats why your test fails.

Can you confirm that your custom node `../mycustom` actually runs in a node-red install?

if it does, then add one to your flow & export it to clip board & use that as your `n1` flow value.

You could also add (inside the try, 1st line) `should(n).be.Object();` to be more specific

---

<div class="post-metadata">

### Author: ![zoujagger](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zoujagger/32/43460_2.png) [@zoujagger](https://discourse.nodered.org/u/zoujagger)
#### Post date: [17 June 2021 10:39 UTC](https://discourse.nodered.org/t/unit-testing-cant-load-node-in-my-it-block/47288/5 "2021-06-17T10:39:33Z")

</div>

test pass when i export my config to clip board as my n1 value.  
thank you guy

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [1 July 2021 10:39 UTC](https://discourse.nodered.org/t/unit-testing-cant-load-node-in-my-it-block/47288/6 "2021-07-01T10:39:35Z")

</div>

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