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

Update Function catch tests to handle async receive

This commit is contained in:
Nick O'Leary 2019-08-21 11:39:34 +01:00
parent b734097d16
commit a17325f028
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 55 additions and 49 deletions

View File

@ -282,13 +282,13 @@ module.exports = function(RED) {
if (!errorMessage) {
errorMessage = err.toString();
}
this.error(errorMessage, msg);
done(errorMessage);
}
else if (typeof err === "string") {
this.error(err, msg);
done(err);
}
else {
this.error(JSON.stringify(err), msg);
done(JSON.stringify(err));
}
}
});

View File

@ -1412,6 +1412,7 @@ describe('function node', function() {
helper.load(functionNode, flow, function () {
var n1 = helper.getNode("n1");
n1.receive({payload: "foo", topic: "bar"});
setTimeout(function() {
try {
helper.log().called.should.be.true();
var logEvents = helper.log().args.filter(function (evt) {
@ -1427,6 +1428,7 @@ describe('function node', function() {
} catch (err) {
done(err);
}
},50);
});
});
it('should catch thrown number', function (done) {
@ -1434,6 +1436,7 @@ describe('function node', function() {
helper.load(functionNode, flow, function () {
var n1 = helper.getNode("n1");
n1.receive({payload: "foo", topic: "bar"});
setTimeout(function() {
try {
helper.log().called.should.be.true();
var logEvents = helper.log().args.filter(function (evt) {
@ -1449,13 +1452,15 @@ describe('function node', function() {
} catch (err) {
done(err);
}
},50);
});
});
it('should catch thrown object (bad practise)', function (done) {
it('should catch thrown object (bad practice)', function (done) {
var flow = [{id: "n1", type: "function", wires: [["n2"]], func: "throw {a:1};"}];
helper.load(functionNode, flow, function () {
var n1 = helper.getNode("n1");
n1.receive({payload: "foo", topic: "bar"});
setTimeout(function() {
try {
helper.log().called.should.be.true();
var logEvents = helper.log().args.filter(function (evt) {
@ -1471,6 +1476,7 @@ describe('function node', function() {
} catch (err) {
done(err);
}
},50);
});
});
});