Skip to content

Commit c2c629d

Browse files
committed
Fixes incorrect passing on of arguments when injected
Fixes #7.
1 parent 79c7c03 commit c2c629d

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ REDstart.inject = function(RED, timeout) {
5757
RED.start = injectedStart;
5858
injected.set(RED, injectedStart);
5959

60+
/* eslint-disable no-invalid-this */
6061
// the function we will be injecting
6162
function injectedStart() {
62-
return start(arguments).then(REDstart(RED, timeout));
63+
return start.apply(this, arguments).then(REDstart(RED, timeout));
6364
}
65+
/* eslint-enable no-invalid-this */
6466
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-embedded-start",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "Enables waiting for flows to have started for embedded Node-RED applications",
55
"main": "index.js",
66
"scripts": {

test/02.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22

3-
var test = require('tape');
3+
var test = require('tape'),
4+
sinon = require('sinon');
45
var path = require('path');
56
var embeddedStart = require('../');
67

@@ -87,3 +88,28 @@ test('can inject wait into RED.start()', function(t) {
8788
return prom;
8889
}).catch(failAndEnd(t));
8990
});
91+
92+
test('arguments with which RED.start() is called are passed on', function(t) {
93+
t.plan(5);
94+
95+
let stub = sinon.stub(RED, "start");
96+
stub.returns(Promise.resolve(42));
97+
98+
embeddedStart.inject(RED);
99+
RED.start("one").then((result) => {
100+
t.equal(result, 42, 'passes on to the stub we presented');
101+
let call = stub.getCall(0);
102+
t.deepEqual(call.args, ["one"], 'correctly passes through one argument');
103+
t.equal(call.thisValue, RED, '"this" is set to RED');
104+
return RED.start("one", "two", "three");
105+
}).then(() => {
106+
let call = stub.getCall(1);
107+
t.deepEqual(call.args, ["one", "two", "three"],
108+
'correctly passes through multiple arguments');
109+
t.equal(call.thisValue, RED, '"this" is set to RED');
110+
RED.start.restore();
111+
}).catch((err) => {
112+
RED.start.restore();
113+
failAndEnd(t)(err);
114+
});
115+
});

0 commit comments

Comments
 (0)