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

let HTML node return empty array for no matching input.

to Close #1582
This commit is contained in:
Dave Conway-Jones 2018-01-26 14:26:49 +00:00
parent d355de509b
commit 8179813fe1
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4
2 changed files with 33 additions and 13 deletions

View File

@ -64,11 +64,12 @@ module.exports = function(RED) {
} }
index++; index++;
}); });
if ((node.as === "single") && (pay.length !== 0)) { if (node.as === "single") { // Always return an array - even if blank
msg.payload = pay; msg.payload = pay;
node.send(msg); node.send(msg);
} }
} catch (error) { }
catch (error) {
node.error(error.message,msg); node.error(error.message,msg);
} }
} }

View File

@ -66,6 +66,25 @@ describe('html node', function() {
}); });
}); });
it('should emit an empty array if no matching elements', function(done) {
fs.readFile(file, 'utf8', function(err, data) {
var flow = [{id:"n1",type:"html",wires:[["n2"]],func:"return msg;"},
{id:"n2", type:"helper"}];
helper.load(htmlNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
msg.should.have.property('topic', 'bar');
msg.should.have.property('payload');
msg.payload.should.be.empty;
done();
});
n1.receive({payload:data,topic:"bar",select:"h4"});
});
});
});
it('should retrieve paragraph contents when specified', function(done) { it('should retrieve paragraph contents when specified', function(done) {
fs.readFile(file, 'utf8', function(err, data) { fs.readFile(file, 'utf8', function(err, data) {
var flow = [{id:"n1",type:"html",wires:[["n2"]],ret:"text",tag:"p"}, var flow = [{id:"n1",type:"html",wires:[["n2"]],ret:"text",tag:"p"},
@ -141,7 +160,7 @@ describe('html node', function() {
}); });
}); });
it('should retrive an attribute from a tag', function(done) { it('should retrieve an attribute from a tag', function(done) {
fs.readFile(file, 'utf8', function(err, data) { fs.readFile(file, 'utf8', function(err, data) {
var flow = [{id:"n1",type:"html",wires:[["n2"]],ret:"attr",tag:"span img"}, var flow = [{id:"n1",type:"html",wires:[["n2"]],ret:"attr",tag:"span img"},
{id:"n2", type:"helper"}]; {id:"n2", type:"helper"}];