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:
parent
2249b9449c
commit
29bd43413a
@ -27,6 +27,9 @@ function createContext(id,seed) {
|
||||
obj.set = function set(key, value) {
|
||||
util.setMessageProperty(data,key,value);
|
||||
}
|
||||
obj.keys = function() {
|
||||
return Object.keys(data);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
@ -119,4 +119,26 @@ describe('context', function() {
|
||||
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");
|
||||
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user