How can I unit test created UI Dashboard widget node?

Hi, :blush:

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,

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'.

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


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

    beforeEach((done) => {

    afterEach((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 {
      "name", "test_node");
            } catch (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.

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

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

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