# How can I unit test created UI Dashboard widget node?

**URL:** https://discourse.nodered.org/t/how-can-i-unit-test-created-ui-dashboard-widget-node/60010
**Category:** Developing Nodes
**Tags:** node-red-dashboard
**Created:** [18 March 2022 01:55 UTC](https://discourse.nodered.org/t/how-can-i-unit-test-created-ui-dashboard-widget-node/60010 "2022-03-18T01:55:45Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![studiobox](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/studiobox/32/55766_2.png) [@studiobox](https://discourse.nodered.org/u/studiobox)
#### Post date: [18 March 2022 01:55 UTC](https://discourse.nodered.org/t/how-can-i-unit-test-created-ui-dashboard-widget-node/60010/1 "2022-03-18T01:55:45Z")

</div>

Hi, 😊

I have create new UI Dashboard widget node. But I have some problem about unit test.

In my new UI Dashboard widget node main function, there are require checked about node-red-dashboard. See below,

```auto
function UiWidgetThermometer(config) {
        let node = this;
        let done = null;
        try {
            if (ui === undefined) {
                ui = RED.require("node-red-dashboard")(RED); <----------- THIS
            }
            RED.nodes.createNode(this, config);
            .....
            ......

```

Below code is my unit test, when I run it, there is an error occured (not pass). I had checked n1 object, result n1 equals 'null'.

```auto
const should = require("should");
const helper = require("node-red-node-test-helper");
const nodeUiWidgetThermometer = require("../nodes/ui_widget_thermometer.js");

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

describe('UI Widget Temperature Node', function () {

    beforeEach((done) => {
        helper.startServer(done);
    });

    afterEach((done) => {
        helper.unload();
        helper.stopServer(done);
    });

    it('should be loaded', (done) => {
        const flow = [
            {
                id: "n1",
                type: "ui_widget_thermometer",
                name: "test_node"
            }
        ];
        helper.load(nodeUiWidgetThermometer, flow, () => {
            const n1 = helper.getNode("n1"); <-------- CHECKED n1 = null 
            try {
                n1.should.have.property("name", "test_node");
                done();
            } catch (err) {
                done(err);
            }
        });
    });
});

```

But If I remove below require node-red-dashboard section in my UI widget code. And then I run unit test again, the result is pass.

```auto
if (ui === undefined) {
     ui = RED.require("node-red-dashboard")(RED);
}

```

So, how can I unit test created UI Dashboard widget node? 🤔

---

<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: [17 May 2022 01:56 UTC](https://discourse.nodered.org/t/how-can-i-unit-test-created-ui-dashboard-widget-node/60010/2 "2022-05-17T01:56:10Z")

</div>

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