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

Add context.keys function to list top-level keys

This commit is contained in:
Nick O'Leary 2017-05-03 20:51:33 +01:00
parent 2249b9449c
commit 29bd43413a
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 25 additions and 0 deletions

View File

@ -27,6 +27,9 @@ function createContext(id,seed) {
obj.set = function set(key, value) { obj.set = function set(key, value) {
util.setMessageProperty(data,key,value); util.setMessageProperty(data,key,value);
} }
obj.keys = function() {
return Object.keys(data);
}
return obj; return obj;
} }

View File

@ -119,4 +119,26 @@ describe('context', function() {
should.not.exist(context.get("foo")); should.not.exist(context.get("foo"));
}) })
it('enumerates context keys', function() {
var context = Context.get("1","flowA");
var keys = context.keys();
keys.should.be.an.Array();
keys.should.be.empty();
context.set("foo","bar");
keys = context.keys();
keys.should.have.length(1);
keys[0].should.eql("foo");
context.set("abc.def","bar");
keys = context.keys();
keys.should.have.length(2);
keys[1].should.eql("abc");
})
}); });