### Example Test Cases for Node-RED "test inject" Node Source: https://github.com/csteinba/node-red-contrib-flowtest/blob/master/flowtest/flowtest.html Provides a practical example of how to define multiple test cases for the "test inject" node. It demonstrates different scenarios including checking for lower case payload, non-null payload, and error property, using the `should` assertion library. ```JavaScript return [ { label: 'is lower case', inject: { payload: 'HELLO WORLD' }, assert: function(msg){ should(msg).have.property('payload', 'hello world'); } }, { label: 'msg payload is not null', inject: { payload: 'hello' }, assert: function(msg) { should(msg.payload).not.be.null(); } }, { label: 'wrong data type', inject: { payload: 123 }, assert: function(msg) { should(msg).have.property('error'); } } ] ``` -------------------------------- ### Node-RED "test inject" Node Configuration UI Source: https://github.com/csteinba/node-red-contrib-flowtest/blob/master/flowtest/flowtest.html Defines the HTML structure for the "test inject" node's configuration dialog, including tabs for 'Tests' and 'Config'. It provides input fields for the node's name and an 'OnStart' checkbox, and a text editor area for defining test cases. ```HTML
``` -------------------------------- ### Node-RED "assert" Node Configuration UI Source: https://github.com/csteinba/node-red-contrib-flowtest/blob/master/flowtest/flowtest.html Defines the HTML structure for the "assert" node's configuration dialog, providing an input field for the node's name. ```HTML
``` -------------------------------- ### Register Node-RED "test inject" Node Source: https://github.com/csteinba/node-red-contrib-flowtest/blob/master/flowtest/flowtest.html Registers the "test inject" node in Node-RED, defining its category, color, default properties (name, onstart, tests), inputs, outputs, icon, and label. It also includes oneditprepare, oneditsave, and oneditcancel functions for handling the node's configuration editor, specifically setting up an Ace editor for test case definition. ```JavaScript RED.nodes.registerType("test inject", { category: "common", color: "#fdd835", defaults: { name: { "value": "" }, onstart: { "value": true }, tests: { "value": "return \[ { \\n \\t label: '', \\n \\t inject: {}, \\n \\t assert: function(msg){} \\n } \]" } }, inputs: 1, outputs: 2, icon: "font-awesome/fa-flask", label: function () { return this.name || "test inject"; }, oneditprepare: function () { // tabs var tabs = RED.tabs.create({ id: "tabs", onchange: function (tab) { $("#tabs-content").children().hide(); $("#" + tab.id).show(); } }); tabs.addTab({ id: "tab-tests", iconClass: "fa fa-flask", label: 'Tests' }); tabs.addTab({ id: "tab-options", iconClass: "fa fa-cog", label: 'Config' }); // test editor this.editor = RED.editor.createEditor({ id: "node-input-tests-editor", mode: "ace/mode/nrjavascript", value: this.tests, globals: { msg: true, context: true, RED: true, util: true, flow: true, global: true, console: true, Buffer: true, setTimeout: true, clearTimeout: true, setInterval: true, clearInterval: true } }); }, oneditsave: function () { this.tests = this.editor.getValue(); this.editor.destroy(); delete this.editor; }, oneditcancel: function () { this.editor.destroy(); delete this.editor; } }); ``` -------------------------------- ### Define Test Cases for Node-RED "test inject" Node Source: https://github.com/csteinba/node-red-contrib-flowtest/blob/master/flowtest/flowtest.html Describes the structure for defining test cases within the "test inject" node. Test cases must be returned as an array, with each test case being an object containing properties like label, inject, assert function, timeout, and delay. ```APIDOC Test case script has to return an array of test cases: return [, , ..., ] Test Case Definition: - label (string): Test case label. - inject (object): Test message. - assert (function(msg)): Assert function. Define your test assertions with NodeJS - Assert or with [should](https://www.npmjs.com/package/should). - timeout (integer): Timeout in milliseconds for the test case to timeout. Default is 2000ms, Max is 10000ms. - delay (integer): Delay for the test case inject. Default is 100 ms. ``` -------------------------------- ### Register Node-RED "assert" Node Source: https://github.com/csteinba/node-red-contrib-flowtest/blob/master/flowtest/flowtest.html Registers the "assert" node in Node-RED, specifying its category, color, default name property, inputs, outputs, icon, and label. This node is designed to verify assertions from test messages. ```JavaScript RED.nodes.registerType("assert", { category: "function", color: "#fdd835", defaults: { name: { "value": "" } }, inputs: 1, outputs: 1, icon: "font-awesome/fa-flask", label: function () { return this.name || "assert"; } }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.