1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00
node-red-nodes/test/function/random/random_spec.js

70 lines
2.3 KiB
JavaScript
Raw Normal View History

var should = require("should");
var helper = require('../../../test/helper.js');
var testNode = require('../../../function/random/random.js');
describe('random node', function() {
"use strict";
beforeEach(function(done) {
helper.startServer(done);
});
afterEach(function(done) {
helper.unload().then(function() {
helper.stopServer(done);
});
});
it("should be loaded with correct defaults", function(done) {
var flow = [{"id":"n1", "type":"random", "name":"random1", "wires":[[]]}];
helper.load(testNode, flow, function() {
var n1 = helper.getNode("n1");
console.log(n1);
n1.should.have.property("low", 1);
n1.should.have.property("high", 10);
n1.should.have.property("inte", false);
done();
});
});
it('should output an integer between -3 and 3', function(done) {
var flow = [{"id":"n1", "type":"random", low:-3, high:3, inte:true, wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(testNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var c = 0;
n2.on("input", function(msg) {
if (c === 0) {
msg.should.have.a.property("payload");
msg.payload.should.be.approximately(0,3);
msg.payload.toString().indexOf(".").should.equal(-1);
done();
}
});
n1.emit("input", {payload:"a"});
});
});
it('should output an float between 20 and 30', function(done) {
var flow = [{"id":"n1", "type":"random", low:20, high:30, inte:false, wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(testNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var c = 0;
n2.on("input", function(msg) {
if (c === 0) {
msg.should.have.a.property("payload");
msg.payload.should.be.approximately(25,5);
msg.payload.toString().indexOf(".").should.not.equal(-1);
done();
}
});
n1.emit("input", {payload:"a"});
});
});
});