mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #3409 from node-red/let-switch-number-test-report-NaN-as-false
switch node - add check for NaN in is of type number to be false
This commit is contained in:
commit
95d3a8cc22
@ -55,6 +55,7 @@ module.exports = function(RED) {
|
|||||||
catch(e) { return false;}
|
catch(e) { return false;}
|
||||||
}
|
}
|
||||||
else if (b === "null") { return a === null; }
|
else if (b === "null") { return a === null; }
|
||||||
|
else if (b === "number") { return typeof a === b && !isNaN(a) }
|
||||||
else { return typeof a === b && !Array.isArray(a) && !Buffer.isBuffer(a) && a !== null; }
|
else { return typeof a === b && !Array.isArray(a) && !Buffer.isBuffer(a) && a !== null; }
|
||||||
},
|
},
|
||||||
'head': function(a, b, c, d, parts) {
|
'head': function(a, b, c, d, parts) {
|
||||||
|
@ -310,6 +310,12 @@ describe('switch Node', function() {
|
|||||||
it('should check if payload if of type number 0', function(done) {
|
it('should check if payload if of type number 0', function(done) {
|
||||||
genericSwitchTest("istype", "number", true, true, 0, done);
|
genericSwitchTest("istype", "number", true, true, 0, done);
|
||||||
});
|
});
|
||||||
|
it('should check if payload if of type number NaN', function(done) {
|
||||||
|
genericSwitchTest("istype", "number", true, false, parseInt("banana"), done);
|
||||||
|
});
|
||||||
|
it('should check if payload if of type number Infinity', function(done) {
|
||||||
|
genericSwitchTest("istype", "number", true, true, 1/0, done);
|
||||||
|
});
|
||||||
it('should check if payload if of type boolean true', function(done) {
|
it('should check if payload if of type boolean true', function(done) {
|
||||||
genericSwitchTest("istype", "boolean", true, true, true, done);
|
genericSwitchTest("istype", "boolean", true, true, true, done);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user