1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #2991 from node-red-hitachi/fix-empty-switch-rule

fix handling of empty switch rules
This commit is contained in:
Nick O'Leary 2021-05-27 12:18:23 +01:00 committed by GitHub
commit 0fb7d3bfc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -217,6 +217,10 @@ module.exports = function(RED) {
function applyRules(node, msg, property,state,done) { function applyRules(node, msg, property,state,done) {
if (!state) { if (!state) {
if (node.rules.length === 0) {
done(undefined, []);
return;
}
state = { state = {
currentRule: 0, currentRule: 0,
elseflag: true, elseflag: true,

View File

@ -1134,4 +1134,20 @@ describe('switch Node', function() {
}); });
}); });
it('should handle empty rule', function(done) {
var flow = [{id:"switchNode1",type:"switch",name:"switchNode",property:"payload",rules:[],checkall:true,outputs:0,wires:[]}];
helper.load(switchNode, flow, function() {
var n1 = helper.getNode("switchNode1");
setTimeout(function() {
var logEvents = helper.log().args.filter(function (evt) {
return evt[0].type == "switch";
});
if (logEvents.length === 0) {
done();
}
}, 150);
n1.receive({payload:1});
});
});
}); });