Skip to content

Commit 4b98144

Browse files
HirokiUchikawaHiroyasuNishiyama
authored andcommitted
Add test cases for function node template(get-keys-in-node-context) (#64)
1 parent 86c794c commit 4b98144

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

Gruntfile.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ module.exports = function (grunt) {
6464
generateNode_getNodeContext: {
6565
command: 'node bin/node-red-nodegen.js samples/get-node-context.js -o ./nodegen'
6666
},
67+
generateNode_getKeysInNodeContext: {
68+
command: 'node bin/node-red-nodegen.js samples/get-keys-in-node-context.js -o ./nodegen'
69+
},
6770
generateNode_getKeysInFlowContext: {
6871
command: 'node bin/node-red-nodegen.js samples/get-keys-in-flow-context.js -o ./nodegen'
6972
},
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// name: get keys in node context
2+
// outputs: 1
3+
msg.payload=context.keys();
4+
return msg;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* Copyright JS Foundation and other contributors, http://js.foundation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
**/
16+
17+
var should = require("should");
18+
var helper = require("node-red-node-test-helper");
19+
var functionNode = require("../../../nodegen/node-red-contrib-get-keys-in-node-context");
20+
21+
describe('node-red-contrib-get-keys-in-node-context', function () {
22+
23+
before(function (done) {
24+
helper.startServer(done);
25+
});
26+
27+
after(function(done) {
28+
helper.stopServer(done);
29+
});
30+
31+
afterEach(function () {
32+
helper.unload();
33+
});
34+
35+
it('should be loaded', function (done) {
36+
var flow = [{id: "n1", type: "get-keys-in-node-context", name: "get-keys-in-node-context" }];
37+
helper.load(functionNode, flow, function () {
38+
var n1 = helper.getNode('n1');
39+
n1.should.have.property('name', 'get-keys-in-node-context');
40+
done();
41+
});
42+
});
43+
it('should get keys in node context', function (done) {
44+
var flow = [{id: "n1", type: "get-keys-in-node-context", wires: [["n2"]]},
45+
{id: "n2", type: "helper"}];
46+
helper.load(functionNode, flow, function () {
47+
var n1 = helper.getNode("n1");
48+
var n2 = helper.getNode("n2");
49+
n1.context().set("count", "0");
50+
n2.on("input", function(msg) {
51+
msg.should.have.property('topic', 'bar');
52+
msg.should.have.property('payload', ['count']);
53+
done();
54+
});
55+
n1.receive({payload: "foo", topic: "bar"});
56+
});
57+
});
58+
});

0 commit comments

Comments
 (0)